From 8229427363b1fa2308de1bff6a0b536268b43082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 17 May 2016 16:47:43 +0200 Subject: [PATCH] wcs: only cache templates for successful requests (#10966) --- template.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/template.py b/template.py index fc17f05..fde4a8f 100644 --- a/template.py +++ b/template.py @@ -10,9 +10,12 @@ class RemoteTemplate(object): self.cache_filepath = os.path.join(self.cache_dirpath, self.cache_key) self.theme_skeleton_url = publisher.get_site_option('theme_skeleton_url') self.css_variant = publisher.get_site_option('css_variant', 'variables') + self.skip_cache = (request.response.status_code != 200) def get_template_content(self): import time, os, threading + if self.skip_cache: + return self.update_content() CACHE_REFRESH_TIMEOUT = 300 try: cache_filepath_mtime = min(( @@ -84,7 +87,8 @@ class RemoteTemplate(object): '[if-any first-user-link][first-user-link][end]', first_user_link) template_content = template_content.replace( '[if-any second-user-link][second-user-link][end]', second_user_link) - self.cache(template_content, page_id=r.headers.get('X-Combo-Page-Id')) + if not self.skip_cache: + self.cache(template_content, page_id=r.headers.get('X-Combo-Page-Id')) return template_content def cache(self, template_body, page_id=None): -- 2.8.1