comparison src/server/pages.py @ 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 6b906b1f419a
comparison
equal deleted inserted replaced
1032:863cc6f97068 1033:c34f08e05cdf
577 577
578 """ 578 """
579 if request.postpath: 579 if request.postpath:
580 # we are not on the final page, no need to go further 580 # we are not on the final page, no need to go further
581 return 581 return
582
583 if request.args:
584 # TODO: requests with args are not cached for now
585 return
586
582 profile = self.getProfile(request) or C.SERVICE_PROFILE 587 profile = self.getProfile(request) or C.SERVICE_PROFILE
583 588
584 if cache_type == C.CACHE_PUBSUB: 589 if cache_type == C.CACHE_PUBSUB:
585 service, node = kwargs['service'], kwargs['node'] 590 service, node = kwargs['service'], kwargs['node']
586 if not node: 591 if not node:
600 d1 = self.host.bridgeCall('psSubscribe', service.full(), node, {}, profile) 605 d1 = self.host.bridgeCall('psSubscribe', service.full(), node, {}, profile)
601 d1.addCallback(self.checkCacheSubscribeCb, service, node) 606 d1.addCallback(self.checkCacheSubscribeCb, service, node)
602 d1.addErrback(self.checkCacheSubscribeEb, service, node) 607 d1.addErrback(self.checkCacheSubscribeEb, service, node)
603 d2 = self.host.bridgeCall('psNodeWatchAdd', service.full(), node, profile) 608 d2 = self.host.bridgeCall('psNodeWatchAdd', service.full(), node, profile)
604 d2.addErrback(self.psNodeWatchAddEb, service, node) 609 d2.addErrback(self.psNodeWatchAddEb, service, node)
605 self._do_cache = [profile, cache_type, service, node] 610 self._do_cache = [self, profile, cache_type, service, node]
606 # we don't return the Deferreds as it is not needed to wait for 611 # we don't return the Deferreds as it is not needed to wait for
607 # the subscription to continue with page rendering 612 # the subscription to continue with page rendering
608 return 613 return
609 614
610 else: 615 else:
762 767
763 if path_args is not None: 768 if path_args is not None:
764 args = [quote(a) for a in path_args] 769 args = [quote(a) for a in path_args]
765 request.postpath = args + request.postpath 770 request.postpath = args + request.postpath
766 771
772 if self._do_cache:
773 # if cache is needed, it will be handled by final page
774 redirect_page._do_cache = self._do_cache
775 self._do_cache = None
776
767 redirect_page.renderPage(request, skip_parse_url=skip_parse_url) 777 redirect_page.renderPage(request, skip_parse_url=skip_parse_url)
768 raise failure.Failure(exceptions.CancelError(u'page redirection is used')) 778 raise failure.Failure(exceptions.CancelError(u'page redirection is used'))
769 779
770 def pageError(self, request, code=C.HTTP_NOT_FOUND, no_body=False): 780 def pageError(self, request, code=C.HTTP_NOT_FOUND, no_body=False):
771 """generate an error page and terminate the request 781 """generate an error page and terminate the request
794 if data is None: 804 if data is None:
795 self.pageError(request) 805 self.pageError(request)
796 data_encoded = data.encode('utf-8') 806 data_encoded = data.encode('utf-8')
797 807
798 if self._do_cache is not None: 808 if self._do_cache is not None:
809 redirected_page = self._do_cache.pop(0)
799 cache = reduce(lambda d, k: d.setdefault(k, {}), self._do_cache, self.cache) 810 cache = reduce(lambda d, k: d.setdefault(k, {}), self._do_cache, self.cache)
800 page_cache = cache[self] = CachePage(data_encoded) 811 page_cache = cache[redirected_page] = CachePage(data_encoded)
801 self._setCacheHeaders(request, page_cache) 812 self._setCacheHeaders(request, page_cache)
802 log.debug(_(u'{page} put in cache for [{profile}]').format( 813 log.debug(_(u'{page} put in cache for [{profile}]').format(
803 page=self, 814 page=self,
804 profile=self._do_cache[0])) 815 profile=self._do_cache[0]))
805 self._do_cache = None 816 self._do_cache = None