diff libervia/server/pages.py @ 1490:774a81a6e8b5

pages: new `useCache` method to check if `no-cache` is used in request
author Goffi <goffi@goffi.org>
date Wed, 26 Jan 2022 10:23:07 +0100
parents 095e94ca6728
children 1671d187e71d
line wrap: on
line diff
--- a/libervia/server/pages.py	Sat Dec 18 17:17:18 2021 +0100
+++ b/libervia/server/pages.py	Wed Jan 26 10:23:07 2022 +0100
@@ -1073,6 +1073,14 @@
     def psNodeWatchAddEb(self, failure_, service, node):
         log.warning(_("Can't add node watched: {msg}").format(msg=failure_))
 
+    def useCache(self, request: server.Request) -> bool:
+        """Indicate if the cache should be used
+
+        test request header to see if it is requested to skip the cache
+        @return: True if cache should be used
+        """
+        return request.getHeader('cache-control') != 'no-cache'
+
     def checkCache(self, request, cache_type, **kwargs):
         """check if a page is in cache and return cached version if suitable
 
@@ -1096,7 +1104,7 @@
             # influencing page results (e.g. search terms)
             log.debug("ignoring cache due to query arguments")
 
-        no_cache = request.getHeader('cache-control') == 'no-cache'
+        no_cache = not self.useCache(request)
 
         profile = self.getProfile(request) or C.SERVICE_PROFILE