Skip to content

Commit

Permalink
PoC with response caching
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Oct 25, 2024
1 parent 609dd99 commit 8801a53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any, Dict, Optional

from flask import Flask, g, redirect, request, Response, send_from_directory, session, url_for
from flask_caching import Cache
from flask_session import Session
from flask_wtf.csrf import CSRFProtect

Expand Down Expand Up @@ -128,6 +129,13 @@ def load_admin_setting() -> Dict[str, Any]:
# Start Flask-Session
Session(app)

# Configure the cache
cache = Cache(app, config={
'CACHE_TYPE': 'FileSystemCache',
'CACHE_DIR': '/tmp',
'CACHE_DEFAULT_TIMEOUT': 300
})

# Start monitoring thread for extracting tech support information
# Monitor signal file can be set to empty to completely disable monitor thread
monitor_enabled: bool = app.config.get("MONITOR_SIGNAL_FILE", "/var/www/yoda/show-tech.sig") != ""
Expand Down
3 changes: 3 additions & 0 deletions general/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
from flask import Blueprint, redirect, render_template, Response, url_for
from flask_wtf.csrf import CSRFError

from app import cache

general_bp = Blueprint('general_bp', __name__,
template_folder='templates/general',
static_folder='static/general',
static_url_path='/assets')


@general_bp.route('/')
@cache.cached(timeout=60)
def index() -> Response:
return render_template('index.html')

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ python-irodsclient==2.2.0
Flask==3.0.2
flask-session==0.6.0
Flask-WTF==1.2.1
Flask-Caching-2.3.0
mod-wsgi==5.0.0
pyjwt[crypto]==2.8.0
requests==2.32.0
Expand Down

0 comments on commit 8801a53

Please sign in to comment.