From 7101592e0f216cc88fd516a3a72499da689de5fc Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 14 Nov 2020 14:03:35 +0100 Subject: [PATCH] Fix: only try to load a cache file from disk if the file exists (#84) 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. --- truewiki/views/page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truewiki/views/page.py b/truewiki/views/page.py index 2e7846d..0c1318f 100644 --- a/truewiki/views/page.py +++ b/truewiki/views/page.py @@ -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()