Skip to content

Commit 7145c1b

Browse files
authored
fix: Set cache headers to refresh after an hour (#20)
1 parent 5c43dbf commit 7145c1b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

action.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def parse_video(self, video: Dict[str, Any]) -> str:
105105
"id": video_id,
106106
"title": video["title"],
107107
"timestamp": int(time.mktime(video["published_parsed"])),
108-
"width": self._card_width,
109108
"background_color": self._background_color,
110109
"title_color": self._title_color,
111110
"stats_color": self._stats_color,
111+
"width": self._card_width,
112112
}
113113
if video_id in self._youtube_data:
114114
content_details = self._youtube_data[video_id]["contentDetails"]

web/app.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from time import gmtime, strftime
23

34
from flask import Flask, render_template, request
45
from flask.wrappers import Response
@@ -62,3 +63,14 @@ def render():
6263
status=status,
6364
mimetype="image/svg+xml",
6465
)
66+
67+
68+
@app.after_request
69+
def add_header(r):
70+
"""Add headers to cache the response no longer than an hour."""
71+
r.headers["Expires"] = strftime(
72+
"%a, %d %b %Y %H:%M:%S GMT", gmtime(datetime.now().timestamp() + 3600)
73+
)
74+
r.headers["Last-Modified"] = strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime())
75+
r.headers["Cache-Control"] = "public, max-age=3600"
76+
return r

0 commit comments

Comments
 (0)