diff --git a/.env.example b/.env.example index 114591a..8c4db0b 100644 --- a/.env.example +++ b/.env.example @@ -3,5 +3,6 @@ CACHE_TIMEOUT_7TV=300 CACHE_TIMEOUT_BTTV=300 CACHE_TIMEOUT_FFZ=300 CACHE_TIMEOUT_TWITCH=300 +MAX_CACHE_TTL=300 TWITCH_CLIENT_ID= TWITCH_SECRET= diff --git a/app.py b/app.py index bba04fa..101cb2c 100644 --- a/app.py +++ b/app.py @@ -27,6 +27,7 @@ load_dotenv() CACHE_CHANNEL_LIMIT = int(os.getenv('CACHE_CHANNEL_LIMIT', 500)) +MAX_CACHE_TTL = int(os.getenv('MAX_CACHE_TTL', 300)) cache = LRUCache(maxsize=CACHE_CHANNEL_LIMIT) @@ -47,6 +48,12 @@ def not_found(error): def rate_limit_exceeded(error): return custom_error(429, 'Rate limit exceeded. Please slow down (60 requests per minute).') +if (MAX_CACHE_TTL > 0): + @app.after_request + def add_header(response): + response.headers['Cache-Control'] = f'max-age={MAX_CACHE_TTL}' + return response + @app.route('/') def index(): return jsonify({