changeset 1033:c34f08e05cdf

pages: cache is now working even after pageRedirect
author Goffi <goffi@goffi.org>
date Mon, 22 Jan 2018 22:19:26 +0100
parents 863cc6f97068
children f82c355ffa6e
files src/server/pages.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/pages.py	Mon Jan 22 22:18:47 2018 +0100
+++ b/src/server/pages.py	Mon Jan 22 22:19:26 2018 +0100
@@ -579,6 +579,11 @@
         if request.postpath:
             # we are not on the final page, no need to go further
             return
+
+        if request.args:
+            # TODO: requests with args are not cached for now
+            return
+
         profile = self.getProfile(request) or C.SERVICE_PROFILE
 
         if cache_type == C.CACHE_PUBSUB:
@@ -602,7 +607,7 @@
                 d1.addErrback(self.checkCacheSubscribeEb, service, node)
                 d2 = self.host.bridgeCall('psNodeWatchAdd', service.full(), node, profile)
                 d2.addErrback(self.psNodeWatchAddEb, service, node)
-                self._do_cache = [profile, cache_type, service, node]
+                self._do_cache = [self, profile, cache_type, service, node]
                 # we don't return the Deferreds as it is not needed to wait for
                 # the subscription to continue with page rendering
                 return
@@ -764,6 +769,11 @@
             args = [quote(a) for a in path_args]
             request.postpath = args + request.postpath
 
+        if self._do_cache:
+            # if cache is needed, it will be handled by final page
+            redirect_page._do_cache = self._do_cache
+            self._do_cache = None
+
         redirect_page.renderPage(request, skip_parse_url=skip_parse_url)
         raise failure.Failure(exceptions.CancelError(u'page redirection is used'))
 
@@ -796,8 +806,9 @@
         data_encoded = data.encode('utf-8')
 
         if self._do_cache is not None:
+            redirected_page = self._do_cache.pop(0)
             cache = reduce(lambda d, k: d.setdefault(k, {}), self._do_cache, self.cache)
-            page_cache = cache[self] = CachePage(data_encoded)
+            page_cache = cache[redirected_page] = CachePage(data_encoded)
             self._setCacheHeaders(request, page_cache)
             log.debug(_(u'{page} put in cache for [{profile}]').format(
                 page=self,