[Checkins] SVN: lovely.viewcache/trunk/src/lovely/viewcache/ Make getCachePath public

Jürgen Kartnaller juergen at kartnaller.at
Thu Apr 5 10:46:45 EDT 2007


Log message for revision 74023:
  Make getCachePath public

Changed:
  U   lovely.viewcache/trunk/src/lovely/viewcache/interfaces.py
  U   lovely.viewcache/trunk/src/lovely/viewcache/view.py

-=-
Modified: lovely.viewcache/trunk/src/lovely/viewcache/interfaces.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/interfaces.py	2007-04-05 14:36:21 UTC (rev 74022)
+++ lovely.viewcache/trunk/src/lovely/viewcache/interfaces.py	2007-04-05 14:46:44 UTC (rev 74023)
@@ -59,6 +59,14 @@
                 at runtime.
             """)
 
+    def getCachePath():
+        """Provide the main key for the cache entry.
+
+        Usually uses the URL without the domain as path.
+        Can be overridden if a view wants to provide a path independent of the
+        URL.
+        """
+
     def cacheHit(self, *args, **kwargs):
         """Called from __call__ if the result is taken from the cache
 

Modified: lovely.viewcache/trunk/src/lovely/viewcache/view.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-04-05 14:36:21 UTC (rev 74022)
+++ lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-04-05 14:46:44 UTC (rev 74023)
@@ -32,26 +32,26 @@
 class CacheMixinBase(object):
 
     cachingOn = True
-    __cachedValue__ = None
     dynamicCachingDeps = ()
     cachingKey = None
+    __cachedValue__ = None
 
-    def getCache(self):
-        return component.queryUtility(IViewCache)
-
-    def _getCachePath(self):
+    def getCachePath(self):
         url = absoluteURL(self, self.request)
         result = '/'.join(url.split('/')[3:])
         if self.dependOnPrincipal:
             result += '/'+self.request.principal.id
         return result
 
+    def _getCache(self):
+        return component.queryUtility(IViewCache)
+
     def _getCachedResult(self):
         self.__cachedValue__ = None
         if self.cachingOn:
-            cache = self.getCache()
+            cache = self._getCache()
             if cache is not None:
-                result = cache.query(self._getCachePath(),
+                result = cache.query(self.getCachePath(),
                                      dict(key=self.cachingKey))
                 if result is not None:
                     self.__cachedValue__ = result
@@ -60,12 +60,12 @@
     def _setCachedResult(self, value):
         self.__cachedValue__ = value
         if self.cachingOn:
-            cache = self.getCache()
+            cache = self._getCache()
             if cache is not None:
                 deps = set(self.staticCachingDeps)
                 deps.update(self.dynamicCachingDeps)
                 cache.set(value,
-                          self._getCachePath(),
+                          self.getCachePath(),
                           dict(key=self.cachingKey),
                           lifetime=self.lifetime,
                           dependencies=deps)



More information about the Checkins mailing list