From fe97fd320ee23bc65dc07b3b2d2702b47b8bfecf Mon Sep 17 00:00:00 2001 From: David Itehua Xalamihua Date: Tue, 29 Apr 2025 14:09:08 -0600 Subject: [PATCH] flask-cache --- main.py | 9 ++++++++- requirements.txt | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index f3a496c..44a6ea9 100644 --- a/main.py +++ b/main.py @@ -19,8 +19,11 @@ import re import json from bs4 import BeautifulSoup from functools import wraps +from flask_caching import Cache app = Flask(__name__) +cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp/flask-formha'}) + bcrypt = Bcrypt(app) # csrf = CSRFProtect(app) @@ -108,7 +111,6 @@ def validate_user_exists(f): return decorated_function - # ################################################################## # # /$$$$$$ /$$$$$$$$ /$$ /$$ /$$$$$$$$ /$$$$$$$ /$$$$$$ /$$ @@ -124,23 +126,28 @@ def validate_user_exists(f): # ################################################################## @app.route('/') +@cache.cached(timeout=3600) def home(): return render_template(v['home'], active_page='home') @app.route('/about-us') +@cache.cached(timeout=43200) def about_us(): return render_template(v['about-us'], active_page='about_us') @app.route('/solutions') +@cache.cached(timeout=43200) def solutions(): return render_template(v['solutions'], active_page='solutions') @app.route('/methodology') +@cache.cached(timeout=43200) def methodology(): return render_template(v['methodology'], active_page='methodology') @app.route('/blog') +@cache.cached(timeout=2880) def blog(): # if any(x in search for x in ["'", '"', " OR ", "--", ";", "1=1"]): diff --git a/requirements.txt b/requirements.txt index 1e93ac0..6dcd958 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,13 @@ bcrypt==4.3.0 beautifulsoup4==4.13.3 blinker==1.9.0 +cachelib==0.13.0 click==8.1.8 dnspython==2.7.0 email_validator==2.2.0 Flask==3.1.0 Flask-Bcrypt==1.0.1 +Flask-Caching==2.3.1 Flask-JWT-Extended==4.7.1 Flask-Mail==0.10.0 Flask-WTF==1.2.2