From 79ac33ec1d80f763c48cc2f83124ec50f8352b9c Mon Sep 17 00:00:00 2001 From: David Itehua Xalamihua Date: Sat, 31 May 2025 16:09:43 -0600 Subject: [PATCH] intento de manejar cache --- README.md | 14 ++++++++++++-- main.py | 18 ++++++++++++------ templates/z_comps/footer.html | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 33a425b..4dec115 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,19 @@ sudo systemctl restart apache2 # IMPORTANTE - Debes de dar permisos a la ruta de archivos UPLOAD (solo se ejecuta una vez) ```bash -sudo chown -R www-data:www-data /var/www/uploads/formha -sudo chmod -R 755 /var/www/uploads/formha +sudo chown -R www-data:www-data /var/www/formha/static/uploads +sudo chmod -R 755 /var/www/formha/static/uploads ``` +# PERMISOS DEL CACHE +Reemplaza www-data por el usuario de Flask/Apache +```bash +sudo mkdir -p /var/www/formha/cache +sudo chown -R www-data:www-data /var/www/formha/cache +sudo chmod 700 /var/www/formha/cache +``` + + # BACKUP DB FORMHA ```psql n_file="db_formha_backup_$(date +"%d_%m_%Y-%H_%M_%S").sql" @@ -73,3 +82,4 @@ pg_dump -h 127.0.0.1 -U postgres -d formha -f "$n_file" ``` + diff --git a/main.py b/main.py index a167779..f565732 100644 --- a/main.py +++ b/main.py @@ -27,18 +27,22 @@ import platform folder_upload = None +folder_cache = None if 'microsoft' in platform.uname().release.lower(): # folder_upload = os.path.join(os.getcwd(), "/static/uploads/") folder_upload = os.path.join(os.getcwd(), "static", "uploads") + folder_cache = os.path.join(os.getcwd(), "cache") elif platform.system() == "Linux": # folder_upload = "/var/www/uploads/formha" folder_upload = "/var/www/formha/static/uploads/" + folder_cache = "/var/www/formha/cache" app = Flask(__name__) -cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp/flask-formha'}) +cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': folder_cache}) +# cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp/flask-formha'}) bcrypt = Bcrypt(app) # csrf = CSRFProtect(app) @@ -151,7 +155,7 @@ def page_not_found(e): return redirect(url_for('home')) @app.route('/') -# @cache.cached(timeout=3600) +@cache.cached(timeout=3600) # 1 hora def home(): q = """ SELECT @@ -172,17 +176,17 @@ def home(): return render_template(v['home'], active_page='home', data=data) @app.route('/about-us') -@cache.cached(timeout=43200) +@cache.cached(timeout=43200) # 12 horas def about_us(): return render_template(v['about-us'], active_page='about_us') @app.route('/solutions') -@cache.cached(timeout=43200) +@cache.cached(timeout=43200) # 12 horas def solutions(): return render_template(v['solutions'], active_page='solutions') @app.route('/methodology') -# @cache.cached(timeout=43200) +@cache.cached(timeout=43200) # 12 horas def methodology(): return render_template(v['methodology'], active_page='methodology') @@ -191,6 +195,7 @@ def blog(): return render_template( v['blog']['all_posts'], active_page='blog' ) @app.route('/blog/api/posts') +@cache.cached(timeout=3600) # 1 hora def api_posts(): q = r""" SELECT @@ -213,7 +218,7 @@ def api_posts(): @app.route('/blog/') @app.route('/blog//src/') -# @cache.cached(timeout=43200) +@cache.cached(timeout=1800) # 30 minutos def blog_post(post_id, source_name=None): # source_name = source_name or 'direct' # source_name = source_name.lower() @@ -261,6 +266,7 @@ def blog_post(post_id, source_name=None): return render_template(v['blog']['post'], data=data) @app.route('/blog/api/count-post-viewed') +@cache.cached(timeout=1800) # 30 minutos def count_posts_viewed(): q = "SELECT id_post, COUNT(id_post) AS count FROM posts_visited GROUP BY id_post ORDER BY id_post;" data = dbUsers.get_all_data_dict(q) diff --git a/templates/z_comps/footer.html b/templates/z_comps/footer.html index bbf0626..91c5d03 100644 --- a/templates/z_comps/footer.html +++ b/templates/z_comps/footer.html @@ -26,7 +26,21 @@ Blvd. Adolfo Ruíz Cortines 2467
C.P. 16035, CDMX, México -
  • +52 xxxx xxxx
  • + +
  • + + + 55 3955 0085 + +
  • +
  • + + + 55 3332 0378 + +
  • + @@ -47,7 +61,7 @@ - +