Skip to content

Commit

Permalink
add flask caching for get projects
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Oct 18, 2024
1 parent da8ddf6 commit f8962d4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app/public/tmp/*
app/public/tmp/*

app/uploads/images/

app/tmp/cache/
.idea/
*.pyc
py3/
Expand Down
5 changes: 4 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from flask_sqlalchemy import SQLAlchemy
from flask_restx import Api

from flask_login import LoginManager, current_user
from flask_login import LoginManager
from flask_caching import Cache
from flask_migrate import Migrate

from app.klang.config import KlangConfig
from app.utils.grew_config import GrewConfig
from app.utils.arborator_parser_config import ParserConfig

cache = Cache()
db = SQLAlchemy()
login_manager = LoginManager()
migrate = Migrate()
Expand Down Expand Up @@ -40,6 +42,7 @@ def create_app(env=None):
db.init_app(app)
migrate.init_app(app, db)
login_manager.init_app(app)
cache.init_app(app)

from .auth import auth as auth_blueprint

Expand Down
3 changes: 3 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

basedir = os.path.abspath(os.path.dirname(__file__))
UPLOAD_FOLDER = "app/tmp/data/"
CACHE_FOLDER = "app/tmp/cache/"
UPLOAD_IMAGE_FOLDER = "app/uploads/images"
MAX_TOKENS = 200000

Expand All @@ -24,6 +25,8 @@ class Config:
SESSION_COOKIE_HTTPONLY = False
SESSION_COOKIE_SECURE = True
MAX_TOKENS = MAX_TOKENS
CACHE_TYPE = 'filesystem'
CACHE_DIR = CACHE_FOLDER

class DevelopmentConfig(Config):
CONFIG_NAME = "dev"
Expand Down
4 changes: 3 additions & 1 deletion app/projects/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import werkzeug

from app import db
from app import cache
from app.utils.grew_utils import GrewService
from app.user.service import UserService
from app.trees.service import TreeValidationService
Expand All @@ -23,9 +24,10 @@
api = Namespace("Project", description="Endpoints for dealing with projects") # noqa

@api.route("/")

class ProjectResource(Resource):
"Project"

@cache.cached(timeout=1200, key_prefix='projects_list')
@responds(schema=ProjectExtendedSchema(many=True), api=api)
def get(self) -> List[ProjectExtendedInterface]:
"""Get all projects"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cryptography==43.0.1
et-xmlfile==1.0.1
Flask==3.0.0
flask-accepts==0.17.4
Flask-Caching==2.3.0
Flask-Cors==4.0.2
Flask-Login==0.6.3
Flask-Migrate==2.5.3
Expand Down

0 comments on commit f8962d4

Please sign in to comment.