[Checkins] SVN: lovely.viewcache/trunk/src/lovely/viewcache/ The cached manager is not needed it duplicates what the viewlet cache is

Jürgen Kartnaller juergen at kartnaller.at
Fri Feb 2 04:38:37 EST 2007


Log message for revision 72321:
  The cached manager is not needed it duplicates what the viewlet cache is
  already doing.
  

Changed:
  D   lovely.viewcache/trunk/src/lovely/viewcache/manager.py
  D   lovely.viewcache/trunk/src/lovely/viewcache/manager.txt
  D   lovely.viewcache/trunk/src/lovely/viewcache/mixin.py
  U   lovely.viewcache/trunk/src/lovely/viewcache/tests.py

-=-
Deleted: lovely.viewcache/trunk/src/lovely/viewcache/manager.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/manager.py	2007-02-02 09:36:11 UTC (rev 72320)
+++ lovely.viewcache/trunk/src/lovely/viewcache/manager.py	2007-02-02 09:38:37 UTC (rev 72321)
@@ -1,84 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Lovely Systems and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-from zope import interface
-from zope import component
-
-from zope.traversing.api import canonicalPath
-from zope.location.interfaces import ILocation
-from zope.viewlet.viewlet import ViewletBase
-from zope.viewlet.manager import ViewletManagerBase
-from zope.viewlet.interfaces import IViewlet
-
-from lovely.viewcache.interfaces import (ICachedViewletManager,
-                                         ICacheableView,
-                                         IViewCache,
-                                        )
-
-
-class CachedViewletManager(ViewletManagerBase):
-    interface.implements(ICachedViewletManager)
-
-    __name__ = u''
-
-    def getCache(self):
-        return component.queryUtility(IViewCache)
-
-    def _getCachePath(self, viewlet):
-        return u'%s/%s/%s'% (canonicalPath(self.context),
-                            unicode(self.__name__),
-                            unicode(viewlet.__name__))
-
-    def _updateViewlets(self):
-        cache = self.getCache()
-        if cache is not None:
-            viewlets = []
-            for viewlet in self.viewlets:
-                # try to get the cached value from the cache
-                if ICacheableView.providedBy(viewlet) and viewlet.cachingOn:
-                    result = cache.query(self._getCachePath(viewlet),
-                                         dict(key=viewlet.key))
-                    if result is not None:
-                        viewlet.__cachedValue__ = result
-                viewlets.append(viewlet)
-            self.viewlets = viewlets
-        for viewlet in self.viewlets:
-            if not hasattr(viewlet, '__cachedValue__'):
-                viewlet.update()
-
-    def render(self):
-        cache = self.getCache()
-        result = []
-        for viewlet in self.viewlets:
-            if not hasattr(viewlet, '__cachedValue__'):
-                viewletResult = viewlet.render()
-                if (    cache is not None
-                    and ICacheableView.providedBy(viewlet)
-                    and viewlet.cachingOn
-                   ):
-                    deps = set(viewlet.staticCachingDeps)
-                    deps.update(viewlet.dynamicCachingDeps)
-                    cache.set(viewletResult,
-                              self._getCachePath(viewlet),
-                              dict(key=viewlet.key),
-                              dependencies=deps)
-                result.append(viewletResult)
-            else:
-                result.append(viewlet.__cachedValue__)
-        return u'\n'.join([r for r in result])
-

Deleted: lovely.viewcache/trunk/src/lovely/viewcache/manager.txt
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/manager.txt	2007-02-02 09:36:11 UTC (rev 72320)
+++ lovely.viewcache/trunk/src/lovely/viewcache/manager.txt	2007-02-02 09:38:37 UTC (rev 72321)
@@ -1,263 +0,0 @@
-======================
-Cached Viewlet Manager
-======================
-
-We provide a viewlet manager which is able to handle the view cache of his
-viewlets.
-
-  >>> from lovely.viewcache.manager import CachedViewletManager
-
-  >>> from zope.app.container.contained import Contained
-  >>> from zope import interface
-  >>> class IContent(interface.Interface):
-  ...     pass
-  >>> class Content(Contained):
-  ...     interface.implements(IContent)
-  >>> content = Content()
-  >>> root[u'content'] = content
-
-  >>> from zope.publisher.browser import TestRequest
-  >>> request = TestRequest() 
-
-  >>> from zope.publisher.interfaces.browser import IBrowserView
-  >>> class View(object):
-  ...     interface.implements(IBrowserView)
-  ...     def __init__(self, context, request):
-  ...         self.context = context
-  ...         self.request = request
-
-  >>> view = View(content, request)
-
-We use the update/render pattern to render the manager. We get no result
-because no viewlet is registered for the manager.
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> manager.render()
-  u''
-
-Now we provide a viewlet and register it for out manager.
-
-  >>> count = 0
-  >>> from lovely.viewcache.interfaces import ICachedViewletManager
-  >>> from lovely.viewcache.mixin import CachableViewMixin
-  >>> from zope.viewlet.viewlet import ViewletBase
-  >>> class TestViewlet(ViewletBase, CachableViewMixin):
-  ...     staticCachingDeps = (1,)
-  ...     def render(self):
-  ...         global count
-  ...         count += 1
-  ...         return 'From TestViewlet %s'% count
-  >>> from zope.security.checker import NamesChecker, defineChecker
-  >>> viewletChecker = NamesChecker(('update', 'render'))
-  >>> defineChecker(TestViewlet, viewletChecker)
-
-  >>> from zope import component
-  >>> from zope.viewlet.interfaces import IViewlet
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> component.provideAdapter(TestViewlet,
-  ...                          adapts=(IContent, IDefaultBrowserLayer,
-  ...                                  IBrowserView, ICachedViewletManager),
-  ...                          provides=IViewlet,
-  ...                          name='test1')
-
-Using the manager again renders the new viewlet.
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> manager.render()
-  u'From TestViewlet 1'
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> manager.render()
-  u'From TestViewlet 2'
-
-We still do not get the viewlet from the cache. This is because we didn't
-provide a cache for the manager. We provide a simple ram cache here.
-
-  >>> from lovely.viewcache.ram import ViewCache
-  >>> from lovely.viewcache.interfaces import IViewCache
-  >>> cache = ViewCache()
-  >>> component.provideUtility(cache, IViewCache)
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> manager.render()
-  u'From TestViewlet 3'
-
-Yipee, we got it.
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> manager.render()
-  u'From TestViewlet 3'
-
-  >>> component.provideAdapter(TestViewlet,
-  ...                          adapts=(IContent, IDefaultBrowserLayer,
-  ...                                  IBrowserView, ICachedViewletManager),
-  ...                          provides=IViewlet,
-  ...                          name='test2')
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  From TestViewlet 3
-  From TestViewlet 4
-
-
-Viewlet Providing A Key For The Cache
--------------------------------------
-
-The viewlet can provide a key to discriminate on internal values.
-
-  >>> class SelectiveViewlet(ViewletBase, CachableViewMixin):
-  ...     @property
-  ...     def key(self):
-  ...         return str(self.request['selector'])
-  ...     def update(self):
-  ...         self.dynamicCachingDeps = (self.request['selector'],)
-  ...     def render(self):
-  ...         global count
-  ...         count += 1
-  ...         return u'%s (selector = %s)'% (count, self.request['selector'])
-  >>> viewletChecker = NamesChecker(('update', 'render'))
-  >>> defineChecker(SelectiveViewlet, viewletChecker)
-  >>> component.provideAdapter(SelectiveViewlet,
-  ...                          adapts=(IContent, IDefaultBrowserLayer,
-  ...                                  IBrowserView, ICachedViewletManager),
-  ...                          provides=IViewlet,
-  ...                          name='selector')
-
-  >>> request.form['selector'] = 1
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  5 (selector = 1)
-  ...
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  5 (selector = 1)
-  ...
-
-Changing the selector must render the viewlet again.
-
-  >>> request.form['selector'] = 2
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  6 (selector = 2)
-  ...
-
-The request with selector 1 is still in the cache.
-
-  >>> request.form['selector'] = 1
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  5 (selector = 1)
-  ...
-
-
-Invalidating Cache Entries
---------------------------
-
-  >>> cache.invalidate(dependencies=(1,))
-
-  >>> request.form['selector'] = 1
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  7 (selector = 1)
-  ...
-
-
-Dynamically disabling the cache
--------------------------------
-
-A view can disable caching using the 'cachingOn' property.
-
-  >>> class CacheSwitchingViewlet(ViewletBase, CachableViewMixin):
-  ...     @property
-  ...     def cachingOn(self):
-  ...         return 'cacheMe' in self.request
-  ...     def render(self):
-  ...         global count
-  ...         count += 1
-  ...         return u'%s (cacheMe = %s)'% (
-  ...                       count, self.request.get('cacheMe', False))
-  >>> viewletChecker = NamesChecker(('update', 'render'))
-  >>> defineChecker(CacheSwitchingViewlet, viewletChecker)
-  >>> component.provideAdapter(CacheSwitchingViewlet,
-  ...                          adapts=(IContent, IDefaultBrowserLayer,
-  ...                                  IBrowserView, ICachedViewletManager),
-  ...                          provides=IViewlet,
-  ...                          name='cacheSwitchin')
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  10 (cacheMe = False)
-  ...
-
-As long as we do not provide 'cacheMe' in the reqeust the viewlet is not
-cached.
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  11 (cacheMe = False)
-  ...
-
-Now the first call with 'cacheMe' set in the reqeust will render it and stores
-the render view in the cache.
-
-  >>> request.form['cacheMe'] = 1
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  12 (cacheMe = 1)
-  ...
-
-Now we get the cached result.
-
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  12 (cacheMe = 1)
-  ...
-
-Removing the 'cacheMe' property will render the view.
-
-  >>> del request.form['cacheMe']
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  13 (cacheMe = False)
-  ...
-
-Setting 'cacheMe' again takes the existing cache entry.
-
-  >>> request.form['cacheMe'] = 1
-  >>> manager = CachedViewletManager(content, request, view)
-  >>> manager.update()
-  >>> print manager.render()
-  12 (cacheMe = 1)
-  ...
-
-
-Configurator
-------------
-
-We also provide a configurator to register a view cache on a site.
-
-  >>> from lovely.viewcache.configurator import RAMViewCacheConfigurator
-  >>> RAMViewCacheConfigurator(root)(None)
-  >>> sm = root.getSiteManager()
-  >>> 'view-cache-RAM' in sm['default']
-  True
-  >>> component.getUtility(IViewCache) is not None
-  True
-

Deleted: lovely.viewcache/trunk/src/lovely/viewcache/mixin.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/mixin.py	2007-02-02 09:36:11 UTC (rev 72320)
+++ lovely.viewcache/trunk/src/lovely/viewcache/mixin.py	2007-02-02 09:38:37 UTC (rev 72321)
@@ -1,33 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Lovely Systems and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from zope import interface
-
-from lovely.viewcache.interfaces import ICacheableView
-
-class CachableViewMixin(object):
-    interface.implements(ICacheableView)
-
-    __parent__ = None
-    __name__ = None
-
-    key = None
-    cachingOn = True
-    staticCachingDeps = ()
-    dynamicCachingDeps = ()
-

Modified: lovely.viewcache/trunk/src/lovely/viewcache/tests.py
===================================================================
--- lovely.viewcache/trunk/src/lovely/viewcache/tests.py	2007-02-02 09:36:11 UTC (rev 72320)
+++ lovely.viewcache/trunk/src/lovely/viewcache/tests.py	2007-02-02 09:38:37 UTC (rev 72321)
@@ -72,10 +72,6 @@
                      setUp=setUp, tearDown=tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
                      ),
-        DocFileSuite('manager.txt',
-                     setUp=setUp, tearDown=tearDown,
-                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
-                     ),
         DocFileSuite('ram.txt',
                      setUp=setUp, tearDown=tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,



More information about the Checkins mailing list