[Checkins] SVN: lovely.viewcache/trunk/src/lovely/viewcache/ Better path for the object identification in the cache.

Jürgen Kartnaller juergen at kartnaller.at
Fri Feb 2 09:53:48 EST 2007


Log message for revision 72325:
  Better path for the object identification in the cache.
  Fixed invalidation.
  Added more info to HOWTOUSE
  

Changed:
  U   lovely.viewcache/trunk/src/lovely/viewcache/HOWTOUSE.txt
  U   lovely.viewcache/trunk/src/lovely/viewcache/README.txt
  U   lovely.viewcache/trunk/src/lovely/viewcache/ftesting.zcml
  U   lovely.viewcache/trunk/src/lovely/viewcache/ram.py
  U   lovely.viewcache/trunk/src/lovely/viewcache/view.py

-=-
Modified: lovely.viewcache/trunk/src/lovely/viewcache/HOWTOUSE.txt
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/HOWTOUSE.txt	2007-02-02 12:29:40 UTC (rev 72324)
+++ lovely.viewcache/trunk/src/lovely/viewcache/HOWTOUSE.txt	2007-02-02 14:53:47 UTC (rev 72325)
@@ -14,10 +14,61 @@
 RAM Based Cache Storage
 ~~~~~~~~~~~~~~~~~~~~~~~
 
+Registering lovely.viewcache.ram.ViewCache as an unnamed utility provides a
+cache storage which stores cache entries in the memory of the running zope
+instance. Please note that you can not use this storage when there is more
+than one zope instance is used with ZEO.
+
+
 ZODB Based Cache Storage
 ~~~~~~~~~~~~~~~~~~~~~~~~
 
+Registering lovely.viewcache.zodb.ViewCache as an unnamed utility provides a
+ZODB based storage to store cache entries. This storage must be used in case
+there is more than one zope instance is running. All zope instances can then
+use the same cache.
 
+If the ZODB storage is used the package lovely.mount is needed. To setup ZODB
+storage for lovely.mount add this to your local.conf or wherever you define
+your databases (maybe on ZEO).
+
+<zodb viewcache>
+  ...
+</zodb>
+
+If you then add the ZODB viewcache you can select from the provided databases.
+Set the database for the viewcache to the newly created database.
+
+If you want to use a RAM bases database just use this :
+
+<zodb viewcache>
+  <mappingstorage>
+  </mappingstorage>
+</zodb>
+
+
 Turning An Existing View Class Into A Cached Class
 --------------------------------------------------
 
+Any existing view class can be turned into a cached class by providing this
+line of code :
+
+  >>> class View(BrowserView):
+  >>>     pass
+  >>> CachedView = cachedView(View)
+
+And for viewlets :
+
+  >>> class Viewlet(ViewletBase):
+  >>>     pass
+  >>> CachedViewlet = cachedViewlet(Viewlet)
+
+In the zcml configuration you now use the newly created class.
+
+
+Providing Cache Keys
+--------------------
+
+The traversal path of the context of the view is used as main key to the cache
+entry. The view can provide a subkey by overriding method 'cachingKey'
+

Modified: lovely.viewcache/trunk/src/lovely/viewcache/README.txt
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/README.txt	2007-02-02 12:29:40 UTC (rev 72324)
+++ lovely.viewcache/trunk/src/lovely/viewcache/README.txt	2007-02-02 14:53:47 UTC (rev 72325)
@@ -74,6 +74,7 @@
 
   >>> view = component.getMultiAdapter((content, request), name='cachedView')
   >>> view.__name__ = 'cachedView'
+  >>> view.__parent__ = content
   >>> from lovely.viewcache.view import CachedViewMixin
   >>> isinstance(view, CachedViewMixin)
   True
@@ -133,6 +134,8 @@
   >>> root[u'content2'] = content2
 
   >>> view2 = component.getMultiAdapter((content2, request), name='cachedView')
+  >>> view2.__name__ = 'cachedView'
+  >>> view2.__parent__ = content2
   >>> view2()
   u'"content 2" is rendered 1 time(s)'
   >>> view2()
@@ -182,6 +185,7 @@
   ...                          name='anotherCachedView')
   >>> view = component.getMultiAdapter((content, request), name='anotherCachedView')
   >>> view.__name__ = 'anotherCachedView'
+  >>> view.__parent__ = content
   >>> view()
   u'"content 1" is rendered 4 time(s)'
 
@@ -200,6 +204,17 @@
 
   >>> from lovely.viewcache.view import cachedViewlet
 
+  >>> content3 = Content(u'content 3')
+  >>> root[u'content3'] = content3
+
+  >>> class FakeManager(object):
+  ...     __name__ = 'manager'
+  ...     def __init__(self, context, request, view):
+  ...         self.context = context
+  ...         self.request = request
+  ...         self.__parent__ = view
+  >>> manager = FakeManager(content3, request, None)
+
   >>> from zope.viewlet.viewlet import ViewletBase
   >>> class Viewlet(ViewletBase):
   ...     def update(self):
@@ -212,9 +227,8 @@
 
 Now we can build a viewlet instance from the cached viewlet.
 
-  >>> content3 = Content(u'content 3')
-  >>> root[u'content3'] = content3
-  >>> viewlet = CachedViewlet(content3, request, None, None)
+  >>> viewlet = CachedViewlet(content3, request, view, manager)
+  >>> viewlet.__name__ = 'viewlet'
   >>> from lovely.viewcache.view import CachedViewletMixin
   >>> isinstance(viewlet, CachedViewletMixin)
   True

Modified: lovely.viewcache/trunk/src/lovely/viewcache/ftesting.zcml
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/ftesting.zcml	2007-02-02 12:29:40 UTC (rev 72324)
+++ lovely.viewcache/trunk/src/lovely/viewcache/ftesting.zcml	2007-02-02 14:53:47 UTC (rev 72325)
@@ -13,11 +13,6 @@
   <include package="zope.viewlet" />
   <include package="zope.viewlet" file="meta.zcml" />
   
-   
-to run the deom we need to include the demo package too
-  <include package="lovely.viewcache.demo" />
-
-  
   <include package="zope.app.securitypolicy" file="meta.zcml" />
 
   <include package="zope.app.server" />

Modified: lovely.viewcache/trunk/src/lovely/viewcache/ram.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/ram.py	2007-02-02 12:29:40 UTC (rev 72324)
+++ lovely.viewcache/trunk/src/lovely/viewcache/ram.py	2007-02-02 14:53:47 UTC (rev 72325)
@@ -40,9 +40,9 @@
             for dep in dependencies:
                 try:
                     obs = s.getEntry(dep, None)
-                    obs += (ob, )
+                    obs += ((ob, key), )
                 except KeyError:
-                    obs = (ob, )
+                    obs = ((ob, key), )
                 s.setEntry(dep, None, obs, lifetime)
 
     def invalidate(self, ob=None, key=None, dependencies=None):
@@ -58,7 +58,7 @@
                     s.invalidate(dep)
                 except KeyError:
                     obs = ()
-                for ob in obs:
+                for ob, key in obs:
                     s.invalidate(ob, key)
         else:
             #TODO: invalidate dependency-indices

Modified: lovely.viewcache/trunk/src/lovely/viewcache/view.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-02-02 12:29:40 UTC (rev 72324)
+++ lovely.viewcache/trunk/src/lovely/viewcache/view.py	2007-02-02 14:53:47 UTC (rev 72325)
@@ -69,7 +69,7 @@
         return component.queryUtility(IViewCache)
 
     def _getCachePath(self):
-        url = absoluteURL(self.context, self.request)
+        url = absoluteURL(self, self.request)
         return '/'.join(url.split('/')[3:])
 
     def _getCachedResult(self):
@@ -122,6 +122,15 @@
 
 class CachedViewletMixin(CacheMixinBase):
 
+    def _getCachePath(self):
+        url = absoluteURL(self.__parent__, self.request)
+        url = '/'.join(url.split('/')[3:])
+        return '%s/%s'% (url,
+                         '/'.join([self.__parent__.__name__,
+                                   self.manager.__name__,
+                                   self.__name__,])
+                        )
+
     def update(self):
         if not self._getCachedResult():
             super(CachedViewletMixin, self).update()



More information about the Checkins mailing list