Skip to content

Commit

Permalink
Add max-age header
Browse files Browse the repository at this point in the history
  • Loading branch information
CrippledByte committed Dec 11, 2023
1 parent 52a4b48 commit 0607dc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
7 changes: 7 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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({
Expand Down

0 comments on commit 0607dc8

Please sign in to comment.