[Zope-Checkins] SVN: Zope/branches/2.12/ - LP #143619: Make sure to remove a RAMCache's contents when the

Jens Vagelpohl jens at dataflake.org
Wed Jun 16 11:58:37 EDT 2010


Log message for revision 113562:
  - LP #143619: Make sure to remove a RAMCache's contents when the
    ZODB object is removed.
  

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  U   Zope/branches/2.12/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
  U   Zope/branches/2.12/src/Products/StandardCacheManagers/RAMCacheManager.py
  U   Zope/branches/2.12/src/Products/StandardCacheManagers/configure.zcml
  U   Zope/branches/2.12/src/Products/StandardCacheManagers/subscribers.py
  U   Zope/branches/2.12/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/doc/CHANGES.rst	2010-06-16 15:58:36 UTC (rev 113562)
@@ -11,6 +11,9 @@
 Bugs Fixed
 ++++++++++
 
+- LP #143619: Make sure to remove a RAMCache's contents when the 
+  ZODB object is removed.
+
 - LP #143403: Prevent accidental acquisition of objectValues during
   recursive ownership changes when the changed object has no 
   objectValues method.

Modified: Zope/branches/2.12/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
===================================================================
--- Zope/branches/2.12/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py	2010-06-16 15:58:36 UTC (rev 113562)
@@ -172,6 +172,10 @@
         ' '
         return self.id
 
+    security.declarePrivate('_remove_data')
+    def _remove_data(self):
+        caches.pop(self.__cacheid)
+
     security.declarePrivate('_resetCacheId')
     def _resetCacheId(self):
         self.__cacheid = '%s_%f' % (id(self), time.time())

Modified: Zope/branches/2.12/src/Products/StandardCacheManagers/RAMCacheManager.py
===================================================================
--- Zope/branches/2.12/src/Products/StandardCacheManagers/RAMCacheManager.py	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/src/Products/StandardCacheManagers/RAMCacheManager.py	2010-06-16 15:58:36 UTC (rev 113562)
@@ -380,6 +380,10 @@
         ' '
         return self.id
 
+    security.declarePrivate('_remove_data')
+    def _remove_data(self):
+        caches.pop(self.__cacheid)
+
     security.declarePrivate('_resetCacheId')
     def _resetCacheId(self):
         self.__cacheid = '%s_%f' % (id(self), time.time())

Modified: Zope/branches/2.12/src/Products/StandardCacheManagers/configure.zcml
===================================================================
--- Zope/branches/2.12/src/Products/StandardCacheManagers/configure.zcml	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/src/Products/StandardCacheManagers/configure.zcml	2010-06-16 15:58:36 UTC (rev 113562)
@@ -6,8 +6,19 @@
     handler="Products.StandardCacheManagers.subscribers.cloned" />
 
   <subscriber
+    for="Products.StandardCacheManagers.RAMCacheManager.RAMCacheManager
+         zope.lifecycleevent.ObjectRemovedEvent"
+    handler="Products.StandardCacheManagers.subscribers.removed" />
+
+
+  <subscriber
     for="Products.StandardCacheManagers.AcceleratedHTTPCacheManager.AcceleratedHTTPCacheManager
          OFS.interfaces.IObjectClonedEvent"
     handler="Products.StandardCacheManagers.subscribers.cloned" />
 
+ <subscriber
+    for="Products.StandardCacheManagers.AcceleratedHTTPCacheManager.AcceleratedHTTPCacheManager
+         zope.lifecycleevent.ObjectRemovedEvent"
+    handler="Products.StandardCacheManagers.subscribers.removed" />
+
 </configure>

Modified: Zope/branches/2.12/src/Products/StandardCacheManagers/subscribers.py
===================================================================
--- Zope/branches/2.12/src/Products/StandardCacheManagers/subscribers.py	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/src/Products/StandardCacheManagers/subscribers.py	2010-06-16 15:58:36 UTC (rev 113562)
@@ -22,3 +22,5 @@
     """ 
     obj._resetCacheId()
 
+def removed(obj, event):
+    obj._remove_data()

Modified: Zope/branches/2.12/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py
===================================================================
--- Zope/branches/2.12/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py	2010-06-16 15:23:36 UTC (rev 113561)
+++ Zope/branches/2.12/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py	2010-06-16 15:58:36 UTC (rev 113562)
@@ -112,7 +112,11 @@
         cache_moved = cachemanager_moved.ZCacheManager_getCache()
         self.assertEqual(cache, cache_moved)
 
-    # XXX test cache is removed if cachemanager is deleted to prevent leaks?
+    def test_cache_deleted_on_remove(self):
+        old_cache = self.cachemanager.ZCacheManager_getCache()
+        self.folder1.manage_delObjects(['cache'])
+        new_cache = self.cachemanager.ZCacheManager_getCache()
+        self.assertNotEqual(old_cache, new_cache)
 
 class AcceleratedHTTPCacheManagerLocationTests(CacheManagerLocationTests):
 



More information about the Zope-Checkins mailing list