def modifyResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) maxage = options.get("maxage", self.maxage) smaxage = options.get("smaxage", self.smaxage) etags = options.get("etags") or self.etags anonOnly = options.get("anonOnly", self.anonOnly) ramCache = options.get("ramCache", self.ramCache) vary = options.get("vary", self.vary) # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ["anonymousOrRandom"] elif "anonymousOrRandom" not in etags: etags = tuple(etags) + ("anonymousOrRandom",) etag = getETagAnnotation(self.published, self.request, etags) lastModified = getLastModifiedAnnotation(self.published, self.request, options["lastModified"]) # Check for cache stop request variables if cacheStop(self.request, rulename): # only stop with etags if configured if etags: etag = "%s%d" % (time.time(), random.randint(0, 1000)) return setCacheHeaders(self.published, self.request, response, etag=etag) # XXX: should there be an else here? Last modified works without extra headers. # Are there other config options? # Do the maxage/smaxage settings allow for proxy caching? proxyCache = smaxage or (maxage and smaxage is None) # Check if the content can be cached in shared caches public = True if ramCache or proxyCache: if etags is not None: if "userid" in etags or "anonymousOrRandom" in etags or "roles" in etags: context = getContext(self.published) portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state") public = portal_state.anonymous() public = public and visibleToRole(self.published, role="Anonymous") if proxyCache and not public: # This is private so keep it out of both shared and browser caches maxage = smaxage = 0 setCacheHeaders( self.published, self.request, response, maxage=maxage, smaxage=smaxage, etag=etag, lastModified=lastModified, vary=vary, ) if ramCache and public: cacheInRAM(self.published, self.request, response, etag=etag, lastModified=lastModified)
def modifyResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) maxage = options.get('maxage') or self.maxage smaxage = options.get('smaxage') or self.smaxage etags = options.get('etags') or self.etags anonOnly = options.get('anonOnly', self.anonOnly) vary = u'Cookie,Accept-Encoding' # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ['anonymousOrRandom'] elif 'anonymousOrRandom' not in etags: etags = tuple(etags) + ('anonymousOrRandom',) etag = getETagAnnotation(self.published, self.request, etags) lastModified = getLastModifiedAnnotation(self.published, self.request, options['lastModified']) # Check for cache stop request variables if cacheStop(self.request, rulename): # only stop with etags if configured if etags: etag = "%s%d" % (time.time(), random.randint(0, 1000)) return setCacheHeaders(self.published, self.request, response, etag=etag) # XXX: should there be an else here? Last modified works without extra headers. # Are there other config options? # Do the maxage/smaxage settings allow for proxy caching? proxyCache = smaxage or (maxage and smaxage is None) setCacheHeaders(self.published, self.request, response, maxage=maxage, smaxage=smaxage, etag=etag, lastModified=lastModified, vary=vary)
def modifyResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) maxage = options.get('maxage') or self.maxage smaxage = options.get('smaxage') or self.smaxage etags = options.get('etags') or self.etags anonOnly = options.get('anonOnly', self.anonOnly) ramCache = options.get('ramCache', self.ramCache) vary = options.get('vary', self.vary) # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ['anonymousOrRandom'] elif 'anonymousOrRandom' not in etags: etags = tuple(etags) + ('anonymousOrRandom',) etag = getETagAnnotation(self.published, self.request, etags) lastModified = getLastModifiedAnnotation(self.published, self.request, options['lastModified']) # Check for cache stop request variables if cacheStop(self.request, rulename): # only stop with etags if configured if etags: etag = "%s%d" % (time.time(), random.randint(0, 1000)) return setCacheHeaders(self.published, self.request, response, etag=etag) # XXX: should there be an else here? Last modified works without extra headers. # Are there other config options? # Do the maxage/smaxage settings allow for proxy caching? proxyCache = smaxage or (maxage and smaxage is None) # Check if the content can be cached in shared caches public = True if ramCache or proxyCache: if etags is not None: if 'userid' in etags or 'anonymousOrRandom' in etags or 'roles' in etags: context = getContext(self.published) portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state') public = portal_state.anonymous() public = public and visibleToRole(self.published, role='Anonymous') if proxyCache and not public: # This is private so keep it out of proxy caches if maxage == 0: # maxage is zero so just omit smaxage smaxage=None else: # maxage is missing or non-zero so expire smaxage smaxage=0 setCacheHeaders(self.published, self.request, response, maxage=maxage, smaxage=smaxage, etag=etag, lastModified=lastModified, vary=vary) if ramCache and public: cacheInRAM(self.published, self.request, response, etag=etag, lastModified=lastModified)
def interceptResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) etags = options.get('etags') or self.etags anonOnly = options.get('anonOnly', self.anonOnly) ramCache = options.get('ramCache', self.ramCache) lastModified = options.get('lastModified', self.lastModified) # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ['anonymousOrRandom'] elif 'anonymousOrRandom' not in etags: etags = tuple(etags) + ('anonymousOrRandom',) etag = getETagAnnotation(self.published, self.request, keys=etags) lastModified = getLastModifiedAnnotation( self.published, self.request, lastModified=lastModified) # Check for cache stop request variables if cacheStop(self.request, rulename): return None # Check if this should be a 304 response if not isModified(self.request, etag=etag, lastModified=lastModified): return notModified( self.published, self.request, response, etag=etag, lastModified=lastModified ) # Check if this is in the ram cache if ramCache: context = getContext(self.published) portal_state = getMultiAdapter( (context, self.request), name=u'plone_portal_state') if portal_state.anonymous(): cached = fetchFromRAMCache( self.request, etag=etag, lastModified=lastModified) if cached is not None: return cachedResponse( self.published, self.request, response, *cached ) return None
def interceptResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) etags = options.get('etags') or self.etags anonOnly = options.get('anonOnly', self.anonOnly) ramCache = options.get('ramCache', self.ramCache) lastModified = options.get('lastModified', self.lastModified) # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ['anonymousOrRandom'] elif 'anonymousOrRandom' not in etags: etags = tuple(etags) + ('anonymousOrRandom', ) etag = getETagAnnotation(self.published, self.request, keys=etags) lastModified = getLastModifiedAnnotation(self.published, self.request, lastModified=lastModified) # Check for cache stop request variables if cacheStop(self.request, rulename): return None # Check if this should be a 304 response if not isModified(self.request, etag=etag, lastModified=lastModified): return notModified( self.published, self.request, response, etag=etag, lastModified=lastModified, ) # Check if this is in the ram cache if ramCache: context = getContext(self.published) portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state') if portal_state.anonymous(): cached = fetchFromRAMCache(self.request, etag=etag, lastModified=lastModified) if cached is not None: return cachedResponse(self.published, self.request, response, *cached) return None
def modifyResponse(self, rulename, response, class_=None): options = lookupOptions(class_ or self.__class__, rulename) maxage = options.get('maxage', self.maxage) smaxage = options.get('smaxage', self.smaxage) etags = options.get('etags') or self.etags anonOnly = options.get('anonOnly', self.anonOnly) ramCache = options.get('ramCache', self.ramCache) vary = options.get('vary', self.vary) # Add the ``anonymousOrRandom`` etag if we are anonymous only if anonOnly: if etags is None: etags = ['anonymousOrRandom'] elif 'anonymousOrRandom' not in etags: etags = tuple(etags) + ('anonymousOrRandom', ) etag = getETagAnnotation(self.published, self.request, etags) lastModified = getLastModifiedAnnotation(self.published, self.request, options['lastModified']) # Check for cache stop request variables if cacheStop(self.request, rulename): # only stop with etags if configured if etags: etag = "%s%d" % (time.time(), random.randint(0, 1000)) return setCacheHeaders(self.published, self.request, response, etag=etag) # XXX: should there be an else here? Last modified works without extra headers. # Are there other config options? # Do the maxage/smaxage settings allow for proxy caching? proxyCache = smaxage or (maxage and smaxage is None) # Check if the content can be cached in shared caches public = True if ramCache or proxyCache: if etags is not None: if 'userid' in etags or 'anonymousOrRandom' in etags or 'roles' in etags: context = getContext(self.published) portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state') public = portal_state.anonymous() public = public and visibleToRole(self.published, role='Anonymous') if proxyCache and not public: # This is private so keep it out of both shared and browser caches maxage = smaxage = 0 setCacheHeaders(self.published, self.request, response, maxage=maxage, smaxage=smaxage, etag=etag, lastModified=lastModified, vary=vary) if ramCache and public: cacheInRAM(self.published, self.request, response, etag=etag, lastModified=lastModified)