[Zope3-checkins] CVS: Zope3/src/zope/app/services - cache.py:1.17 configure.zcml:1.56 servicenames.py:1.11

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 14:35:01 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv19346/services

Modified Files:
	cache.py configure.zcml servicenames.py 
Log Message:
Just to make it worth the effort, here is the rewrite of the Caching Service
to use local utilities. I am amazed how much cruft can go away. There are
still some dead chickens left that can be easily fixed by providing a 
default overview screen for these services and remodeling the local utility
service a bit.

Jim,

noone has complained about the changes yet. Are you guys at ZC having a fit
with it? I think in general people just not use these components heavily
yet and it is no big deal to create them, since their data does not contain
much programming logic (i.e. they are easily recreated) and there are only
a few around ata time usually.


=== Zope3/src/zope/app/services/cache.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/services/cache.py:1.16	Sun Jun 22 20:31:31 2003
+++ Zope3/src/zope/app/services/cache.py	Tue Aug 19 13:34:24 2003
@@ -15,106 +15,61 @@
 
 $Id$
 """
-
 from persistence import Persistent
+from zope.app import zapi
 from zope.app.component.nextservice import queryNextService
-from zope.app.interfaces.cache.cache import ICache, ICachingService
+from zope.app.interfaces.cache import ICache
 from zope.app.interfaces.event import IObjectModifiedEvent
-from zope.app.interfaces.services.cache import ICacheRegistration
-from zope.app.interfaces.services.registration import INameComponentRegistry
-from zope.app.interfaces.services.event import IEventChannel
+from zope.app.interfaces.services.cache import ILocalCachingService
 from zope.app.interfaces.services.service import ISimpleService
-from zope.app.services.registration import NameComponentRegistry
-from zope.app.services.registration import NamedComponentRegistration
 from zope.app.services.event import ServiceSubscriberEventChannel
+from zope.app.services.servicenames import Caching, Utilities
 from zope.component import getService
 from zope.context import ContextMethod
 from zope.interface import implements
 
-class ILocalCachingService(ICachingService, IEventChannel,
-                           INameComponentRegistry):
-    """TTW manageable caching service"""
-
-
-class CachingService(ServiceSubscriberEventChannel, NameComponentRegistry):
+class CachingService(ServiceSubscriberEventChannel, Persistent):
 
     implements(ILocalCachingService, ISimpleService)
 
     _subscribeToServiceInterface = IObjectModifiedEvent
 
     def __init__(self):
-        # XXX If we know that all the superclasses do the right thing in
-        #     __init__ with respect to calling
-        #     super(ClassName, self).__init__(*args, **kw), then we can
-        #     replace the following with just a call to super.
-        # XXX Disagree.  __init__ doesn't always have the same signature,
-        #     hence cllaborative super doesn't apply to __init__, at least
-        #     not in general.  (It may work by convention for Fields.)
-        #     --Guido
-        Persistent.__init__(self)
-        ServiceSubscriberEventChannel.__init__(self)
-        NameComponentRegistry.__init__(self)
+        super(CachingService, self).__init__()
 
-    def getCache(wrapped_self, name):
+    def getCache(self, name):
         'See ICachingService'
-        cache = wrapped_self.queryActiveComponent(name)
-        if cache:
-            return cache
-        service = queryNextService(wrapped_self, "Caching")
+        utilities = zapi.getService(self, Utilities)
+        matching = utilities.getRegisteredMatching(ICache)
+        matching = filter(lambda m: m[1] == name, matching)
+        if matching and matching[0][2].active() is not None:
+            return matching[0][2].active().getComponent()
+        service = queryNextService(self, Caching)
         if service is not None:
             return service.getCache(name)
         raise KeyError, name
     getCache = ContextMethod(getCache)
 
-    def queryCache(wrapped_self, name, default=None):
+    def queryCache(self, name, default=None):
         'See ICachingService'
         try:
-            return wrapped_self.getCache(name)
+            return self.getCache(name)
         except KeyError:
             return default
     queryCache = ContextMethod(queryCache)
 
-    def getAvailableCaches(wrapped_self):
+    def getAvailableCaches(self):
         'See ICachingService'
-        caches = {}
-        for name in wrapped_self.listRegistrationNames():
-            registry = wrapped_self.queryRegistrations(name)
-            if registry.active() is not None:
-                caches[name] = 0
-        service = queryNextService(wrapped_self, "Caching")
+        caches = []
+        utilities = zapi.getService(self, Utilities)
+        matching = utilities.getRegisteredMatching(ICache)
+        for match in matching:
+            if match[2].active() is not None:
+                caches.append(match[1])
+        service = queryNextService(self, Caching)
         if service is not None:
             for name in service.getAvailableCaches():
-                caches[name] = 0
-        return caches.keys()
+                if name not in caches:
+                    caches.append(name)
+        return caches
     getAvailableCaches = ContextMethod(getAvailableCaches)
-
-
-class CacheRegistration(NamedComponentRegistration):
-
-    __doc__ = ICacheRegistration.__doc__
-
-    implements(ICacheRegistration)
-
-    serviceType = 'Caching'
-
-    label = "Cache"
-
-    def activated(wrapped_self):
-        cache = wrapped_self.getComponent()
-        service = getService(wrapped_self, 'Caching')
-        service.subscribe(cache, IObjectModifiedEvent)
-    activated = ContextMethod(activated)
-
-    def deactivated(wrapped_self):
-        cache = wrapped_self.getComponent()
-        service = getService(wrapped_self, 'Caching')
-        service.unsubscribe(cache, IObjectModifiedEvent)
-        cache.invalidateAll()
-    deactivated = ContextMethod(deactivated)
-
-    def getInterface(self):
-        return ICache
-
-
-# XXX Pickle backward compatability
-CacheConfiguration = CacheRegistration


=== Zope3/src/zope/app/services/configure.zcml 1.55 => 1.56 ===
--- Zope3/src/zope/app/services/configure.zcml:1.55	Tue Aug 19 03:09:53 2003
+++ Zope3/src/zope/app/services/configure.zcml	Tue Aug 19 13:34:24 2003
@@ -196,30 +196,12 @@
 <!-- Caching Service -->
 
   <content class="zope.app.services.cache.CachingService">
-    <factory id="CachingService" permission="zope.ManageServices" />
+    <factory 
+          id="zope.services.CachingService" 
+          permission="zope.ManageServices" />
       <require
           permission="zope.View"
-          interface="zope.app.interfaces.cache.cache.ICachingService"
-          attributes="queryRegistrations queryRegistrationsFor
-                      listRegistrationNames" />
-      <require
-          permission="zope.ManageServices"
-          interface="zope.app.interfaces.container.IContainer" />
-    </content>
-
-  <content class="zope.app.services.cache.CacheRegistration">
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.interfaces.services.cache.ICacheRegistration"
-        set_attributes="name componentPath permission"
-        set_schema=
-            "zope.app.interfaces.services.registration.IRegistration" />
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.interfaces.container.IAddNotifiable" />
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.interfaces.container.IDeleteNotifiable" />
+          interface="zope.app.interfaces.cache.ICachingService" />
     </content>
 
 <!-- Service Manager -->
@@ -484,11 +466,6 @@
 <fssync:adapter
     class=".zpt.ZPTTemplate"
     factory=".zpt.ZPTPageAdapter"
-    />
-
-<fssync:adapter
-    class=".cache.CacheRegistration"
-    factory=".registration.ComponentRegistrationAdapter"
     />
 
 <fssync:adapter


=== Zope3/src/zope/app/services/servicenames.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/services/servicenames.py:1.10	Fri Aug 15 20:44:08 2003
+++ Zope3/src/zope/app/services/servicenames.py	Tue Aug 19 13:34:24 2003
@@ -21,6 +21,7 @@
 
 Authentication = 'Authentication'
 BrowserMenu = 'BrowserMenu'
+Caching = 'Caching'
 DAVSchema = 'DAVSchema'
 EventPublication = 'EventPublication'
 EventSubscription = 'Subscription'




More information about the Zope3-Checkins mailing list