[Checkins] SVN: lovely.viewcache/trunk/src/lovely/viewcache/ Simplified version

Jürgen Kartnaller juergen at kartnaller.at
Thu Apr 5 10:36:21 EDT 2007


Log message for revision 74022:
  Simplified version

Changed:
  U   lovely.viewcache/trunk/src/lovely/viewcache/README.txt
  U   lovely.viewcache/trunk/src/lovely/viewcache/view.py

-=-
Modified: lovely.viewcache/trunk/src/lovely/viewcache/README.txt
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/README.txt	2007-04-05 13:15:06 UTC (rev 74021)
+++ lovely.viewcache/trunk/src/lovely/viewcache/README.txt	2007-04-05 14:36:21 UTC (rev 74022)
@@ -162,14 +162,10 @@
 
 A cached view provides the static dependencies via the 'staticCachingDeps'
 attribute. The static dependency can be set as a class member or can be
-provided when creating the cached view. It can not be cached during runtime.
+provided when creating the cached view.
 
   >>> view.staticCachingDeps
   ('content',)
-  >>> view.staticCachingDeps = ('not possible',)
-  Traceback (most recent call last):
-  ...
-  AttributeError: can't set attribute
 
 
 Providing dynamic dependencies

Modified: lovely.viewcache/trunk/src/lovely/viewcache/view.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-04-05 13:15:06 UTC (rev 74021)
+++ lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-04-05 14:36:21 UTC (rev 74022)
@@ -31,36 +31,11 @@
 
 class CacheMixinBase(object):
 
-    _cachingOn = True
+    cachingOn = True
     __cachedValue__ = None
-    _dynamicCachingDeps = ()
+    dynamicCachingDeps = ()
+    cachingKey = None
 
-    @apply
-    def cachingOn():
-        def get(self):
-            return getattr(super(CacheMixinBase, self),
-                           'cachingOn',
-                           self._cachingOn)
-        def set(self, value):
-            self._cachingOn = value
-        return property(get, set)
-
-    @property
-    def staticCachingDeps(self):
-        return getattr(super(CacheMixinBase, self),
-                       'staticCachingDeps',
-                       self._staticCachingDeps)
-
-    @apply
-    def dynamicCachingDeps():
-        def get(self):
-            return getattr(super(CacheMixinBase, self),
-                                 'dynamicCachingDeps',
-                                 self._dynamicCachingDeps)
-        def set(self, value):
-            self._dynamicCachingDeps = value
-        return property(get, set)
-
     def getCache(self):
         return component.queryUtility(IViewCache)
 
@@ -77,9 +52,7 @@
             cache = self.getCache()
             if cache is not None:
                 result = cache.query(self._getCachePath(),
-                                     dict(key=getattr(self,
-                                                     'cachingKey',
-                                                     None)))
+                                     dict(key=self.cachingKey))
                 if result is not None:
                     self.__cachedValue__ = result
         return self.__cachedValue__ is not None
@@ -93,12 +66,12 @@
                 deps.update(self.dynamicCachingDeps)
                 cache.set(value,
                           self._getCachePath(),
-                          dict(key=getattr(self, 'cachingKey', None)),
+                          dict(key=self.cachingKey),
                           lifetime=self.lifetime,
                           dependencies=deps)
 
 
-class CachedViewMixin(CacheMixinBase):
+class CachedViewMixin(object):
     interface.implements(ICacheableView)
 
     def __call__(self, *args, **kwargs):
@@ -109,7 +82,7 @@
             if c:
                 c(*args, **kwargs)
         else:
-            result = super(CacheMixinBase, self).__call__(*args, **kwargs)
+            result = super(CachedViewMixin, self).__call__(*args, **kwargs)
             self._setCachedResult(result)
         return self.__cachedValue__
 
@@ -119,18 +92,18 @@
     """A factory to provide a view which is possibly in the view cache."""
     klass = ViewClass
     if ICacheableView not in interface.implementedBy(klass):
-        attrs = dict(_staticCachingDeps=dependencies,
+        attrs = dict(staticCachingDeps=dependencies,
                      lifetime = (minAge, maxAge),
                      dependOnPrincipal=dependOnPrincipal,
                      __name__=None,
                     )
         klass = type('<ViewCache for %s>'% ViewClass.__name__,
-                     (CachedViewMixin, ViewClass, ),
+                     (CachedViewMixin, ViewClass, CacheMixinBase),
                      attrs)
     return klass
 
 
-class CachedViewletMixin(CacheMixinBase):
+class CachedViewletMixin(object):
     interface.implements(ICacheableViewlet)
 
     def update(self):
@@ -157,13 +130,13 @@
     klass = ViewClass
     if ICacheableView not in interface.implementedBy(klass):
         # our class is not cached, so make it a cached class
-        attrs = dict(_staticCachingDeps=dependencies,
+        attrs = dict(staticCachingDeps=dependencies,
                      lifetime = (minAge, maxAge),
                      dependOnPrincipal=dependOnPrincipal,
                      __name__=None,
                     )
         klass = type('<ViewletCache for %s>'% ViewClass.__name__,
-                     (CachedViewletMixin, ViewClass, ),
+                     (CachedViewletMixin, ViewClass, CacheMixinBase),
                      attrs)
     return klass
 



More information about the Checkins mailing list