[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/CachingService - CacheConfiguration.py:1.1 ICacheConfiguration.py:1.1 CachingService.py:1.4 configure.zcml:1.3

Marius Gedminas mgedmin@codeworks.lt
Thu, 12 Dec 2002 10:28:47 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/CachingService
In directory cvs.zope.org:/tmp/cvs-serv24277/lib/python/Zope/App/OFS/Services/CachingService

Modified Files:
	CachingService.py configure.zcml 
Added Files:
	CacheConfiguration.py ICacheConfiguration.py 
Log Message:
Caching service now uses the new configuration infrastructure
Added invalidateAll to Zope.App.Caching.ICache



=== Added File Zope3/lib/python/Zope/App/OFS/Services/CachingService/CacheConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""A configuration for a cache.

$Id: CacheConfiguration.py,v 1.1 2002/12/12 15:28:16 mgedmin Exp $
"""

from ICacheConfiguration import ICacheConfiguration
from Zope.App.OFS.Services.Configuration import NamedComponentConfiguration
from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
from Zope.ComponentArchitecture import getService
from Zope.Event.IObjectEvent import IObjectModifiedEvent
from Zope.ContextWrapper import ContextMethod

class CacheConfiguration(NamedComponentConfiguration):

    __doc__ = ICacheConfiguration.__doc__

    __implements__ = (ICacheConfiguration,
                      NamedComponentConfiguration.__implements__)

    status = ConfigurationStatusProperty('Caching')

    label = "Cache"

    def __init__(self, *args, **kw):
        super(CacheConfiguration, self).__init__(*args, **kw)

    def activated(self):
        cache = self.getComponent()
        service = getService(self, 'Caching')
        service.subscribe(cache, IObjectModifiedEvent)

    activated = ContextMethod(activated)

    def deactivated(self):
        cache = self.getComponent()
        service = getService(self, 'Caching')
        service.unsubscribe(cache, IObjectModifiedEvent)
        cache.invalidateAll()

    deactivated = ContextMethod(deactivated)


=== Added File Zope3/lib/python/Zope/App/OFS/Services/CachingService/ICacheConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""A configuration for a cache.

$Id: ICacheConfiguration.py,v 1.1 2002/12/12 15:28:16 mgedmin Exp $
"""

from Zope.App.OFS.Services.ConfigurationInterfaces \
     import INamedComponentConfiguration

class ICacheConfiguration(INamedComponentConfiguration):
    """Cache configuration

    Cache configurations are dependent on the caches that they configure. They
    register themselves as component dependents.
    """


=== Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py:1.3	Fri Dec  6 13:03:31 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py	Thu Dec 12 10:28:16 2002
@@ -15,74 +15,66 @@
 
 $Id$
 """
-from types import TupleType
-from Zope.App.Caching.ICache import ICache
+from Persistence import Persistent
 from Zope.App.Caching.ICachingService import ICachingService
 from Zope.App.ComponentArchitecture.NextService import queryNextService
-from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
-from Zope.App.OFS.Container.IContainer import IHomogenousContainer, IContainer
+from Zope.App.OFS.Services.ConfigurationInterfaces import INameConfigurable
+from Zope.App.OFS.Services.Configuration import NameConfigurable
 from Zope.App.OFS.Services.LocalEventService.ProtoServiceEventChannel \
      import ProtoServiceEventChannel
 from Zope.ContextWrapper import ContextMethod
-from Zope.Event.EventChannel import EventChannel
 from Zope.Event.IEventChannel import IEventChannel
 from Zope.Event.IObjectEvent import IObjectModifiedEvent
 
 
-class ILocalCachingService(ICachingService, IContainer,
-                           IHomogenousContainer,
-                           IEventChannel):
+class ILocalCachingService(ICachingService, IEventChannel, INameConfigurable):
     """TTW manageable caching service"""
 
 
-class CachingService(BTreeContainer, ProtoServiceEventChannel):
+class CachingService(Persistent, ProtoServiceEventChannel, NameConfigurable):
 
     __implements__ = ILocalCachingService, ProtoServiceEventChannel.__implements__
 
     _subscribeToServiceInterface = IObjectModifiedEvent
 
     def __init__(self):
-        BTreeContainer.__init__(self)
+        Persistent.__init__(self)
         ProtoServiceEventChannel.__init__(self)
-
-    def __nonzero__(self):
-        # XXX otherwise 'if service:' in getService() fails when len(service) == 0
-        return 1
+        NameConfigurable.__init__(self)
 
     def getCache(self, name):
         'See Zope.App.Caching.ICachingService.ICachingService'
-        return self.__getitem__(name)
+        cache = self.queryActiveComponent(name)
+        if cache:
+            return cache
+        service = queryNextService(self, "Caching")
+        if service is not None:
+            return service.getCache(name)
+        raise KeyError, name
+
+    getCache = ContextMethod(getCache)
 
     def queryCache(self, name, default=None):
         'See Zope.App.Caching.ICachingService.ICachingService' 
-        cache = self.get(name, default)
-        if cache is not default:
-            return cache
-        return default
+        try:
+            return self.getCache(name)
+        except KeyError:
+            return default
+
+    queryCache = ContextMethod(queryCache)
 
     def getAvailableCaches(self):
         'See Zope.App.Caching.ICachingService.ICachingService'
-        caches = list(self.keys())
+        caches = {}
+        for name in self.listConfigurationNames():
+            registry = self.queryConfigurations(name)
+            if registry.active() is not None:
+                caches[name] = 0
         service = queryNextService(self, "Caching")
         if service is not None:
-            caches.append(service.getAvailableCaches())
-        return caches
+            for name in service.getAvailableCaches():
+                caches[name] = 0
+        return caches.keys()
+
     getAvailableCaches = ContextMethod(getAvailableCaches)
 
-    def isAddable(self, interfaces):
-        'See Zope.App.OFS.Container.IContainer.IHomogenousContainer'
-        if type(interfaces) != TupleType:
-            interfaces = (interfaces,)
-        if ICache in interfaces:
-            return 1
-        return 0
-
-    def setObject(self, key, object):
-        "See Zope.App.OFS.Container.IContainer.IWriteContainer"
-        self.subscribe(object, IObjectModifiedEvent)
-        BTreeContainer.setObject(self, key, object)
-
-    def __delitem__(self, key):
-        "See Zope.App.OFS.Container.IContainer.IWriteContainer"
-        self.unsubscribe(self[key], IObjectModifiedEvent)
-        BTreeContainer.__delitem__(self, key)


=== Zope3/lib/python/Zope/App/OFS/Services/CachingService/configure.zcml 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Services/CachingService/configure.zcml:1.2	Sat Nov 30 13:36:38 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/CachingService/configure.zcml	Thu Dec 12 10:28:16 2002
@@ -5,11 +5,28 @@
     <factory id="CachingService" permission="Zope.ManageServices" />
       <require
           permission="Zope.View"
-          interface="Zope.App.Caching.ICachingService." />
+          interface="Zope.App.Caching.ICachingService."
+          attributes="queryConfigurations queryConfigurationsFor
+                      listConfigurationNames" />
       <require
           permission="Zope.ManageServices"
           interface="Zope.App.OFS.Container.IContainer." />
       <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
+  </content>
+
+  <content class=".CacheConfiguration.">
+    <require
+        permission="Zope.ManageServices"
+        interface=".ICacheConfiguration."
+        set_attributes="name componentPath"
+        set_schema=
+            "Zope.App.OFS.Services.ConfigurationInterfaces.IConfiguration" />
+    <require
+        permission="Zope.ManageServices"
+        interface="Zope.App.OFS.Container.IAddNotifiable." />
+    <require
+        permission="Zope.ManageServices"
+        interface="Zope.App.OFS.Container.IDeleteNotifiable." />
   </content>
 
   <include package=".Views" />