[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Caching - AnnotationCacheable.py:1.2 ICacheable.py:1.2 configure.zcml:1.4

Albertas Agejevas alga@codeworks.lt
Wed, 9 Oct 2002 09:09:14 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Caching
In directory cvs.zope.org:/tmp/cvs-serv4391

Modified Files:
	AnnotationCacheable.py ICacheable.py configure.zcml 
Log Message:
Views for ICacheable

=== Zope3/lib/python/Zope/App/Caching/AnnotationCacheable.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Caching/AnnotationCacheable.py:1.1	Thu Oct  3 06:14:12 2002
+++ Zope3/lib/python/Zope/App/Caching/AnnotationCacheable.py	Wed Oct  9 09:08:44 2002
@@ -13,7 +13,7 @@
 ##############################################################################
 """An adapter of annotatable objects."""
 
-from Zope.ComponentArchitecture import getAdapter
+from Zope.ComponentArchitecture import getAdapter, getService
 from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
 from Zope.App.Caching.ICacheable import ICacheable
 
@@ -34,5 +34,13 @@
 
     def setCacheId(self, id):
         """See Zope.App.Caching.ICacheable"""
+        # Remove object from old cache
+        old_cache_id = self.getCacheId()
+        if old_cache_id and old_cache_id != id:
+            service = getService(self._context, "Caching")
+            cache = service.getCache(old_cache_id)
+            cache.invalidate(self._context)
         annotations = getAdapter(self._context, IAnnotations)
         annotations[annotation_key] = id
+
+    cacheId = property(getCacheId, setCacheId, None, "Associated cache name")


=== Zope3/lib/python/Zope/App/Caching/ICacheable.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Caching/ICacheable.py:1.1	Thu Oct  3 05:41:23 2002
+++ Zope3/lib/python/Zope/App/Caching/ICacheable.py	Wed Oct  9 09:08:44 2002
@@ -15,9 +15,26 @@
 $Id$
 """
 from Interface import Interface
+from Zope.ContextWrapper import ContextMethod
+from Zope.ComponentArchitecture import getService
+import Zope.Schema
+
+class CacheName(Zope.Schema.Text):
+    """Cache Name"""
+
+    def items(self):
+        """Note that this method works only if the Field is context wrapped."""
+        caching_service = getService(self, "Caching")
+        return [('', '(None)')] + caching_service.getAvailableCaches() # FIXME: i18n
+
+    items = ContextMethod(items)
 
 class ICacheable(Interface):
     """Object that can be associated with a cache manager."""
+
+    cacheId = CacheName(title=u"Cache Name",
+                        description=u"The name of the cache used for this object.",
+                        required=False)
 
     def getCacheId():
         """Gets the associated cache manager ID."""


=== Zope3/lib/python/Zope/App/Caching/configure.zcml 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Caching/configure.zcml:1.3	Fri Oct  4 11:17:47 2002
+++ Zope3/lib/python/Zope/App/Caching/configure.zcml	Wed Oct  9 09:08:44 2002
@@ -10,6 +10,8 @@
            provides=".ICacheable."
            for="Zope.App.OFS.Annotation.IAnnotatable." />
 
+  <include package=".Views" />
+
 </zopeConfigure>