Skip to content

Commit

Permalink
Fix: only try to load a cache file from disk if the file exists (#84)
Browse files Browse the repository at this point in the history
This could happen if the first time a page was loaded, was done
by someone who was logged in. This does update LAST_TIME_RENDERED
for browser if-modified-since caching, but does not write the
file to disk. If a non-logged-in user visit the page after, the
page is not on disk.
  • Loading branch information
TrueBrain authored Nov 14, 2020
1 parent 99a63de commit 7101592
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion truewiki/views/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def view(user, page: str, if_modified_since) -> web.Response:
# We already rendered this page before. If the browser has it in his
# cache, he can simply reuse that if we haven't rendered since.
response = web.HTTPNotModified()
elif not user and cache_filename:
elif not user and cache_filename and os.path.exists(cache_filename):
# We already rendered this page to disk. Serve from there.
with open(cache_filename) as fp:
body = fp.read()
Expand Down

0 comments on commit 7101592

Please sign in to comment.