From 98a19a1ed8efa82bef9f95eba993b620993fdadf Mon Sep 17 00:00:00 2001 From: Felix Blanke Date: Sun, 27 Aug 2023 11:39:54 +0200 Subject: [PATCH] Add caching --- wsgi.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wsgi.py b/wsgi.py index bd1caba..d6ed0e0 100644 --- a/wsgi.py +++ b/wsgi.py @@ -2,10 +2,18 @@ import datetime import pandas as pd from flask import Flask, render_template, request +from flask_caching import Cache from download_digital import construct_dataframe, get_bez_data +config = { + "CACHE_TYPE": "SimpleCache", # Flask-Caching related configs + "CACHE_DEFAULT_TIMEOUT": 300, +} + app = Flask(__name__) +app.config.from_mapping(config) +cache = Cache(app) def get_tables(url: str) -> tuple[pd.DataFrame, pd.DataFrame]: @@ -25,6 +33,7 @@ def get_tables(url: str) -> tuple[pd.DataFrame, pd.DataFrame]: @app.route("/") +@cache.cached(timeout=50) def tables( url: str = "https://beschaeftigtenbefragung.verdi.de/", ):