Log message for revision 109931: forward port r109929: fix for lp #534653
Changed: _U Zope/trunk/ U Zope/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py U Zope/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py A Zope/trunk/src/Products/StandardCacheManagers/configure.zcml A Zope/trunk/src/Products/StandardCacheManagers/subscribers.py A Zope/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py -=- Property changes on: Zope/trunk ___________________________________________________________________ Added: svn:mergeinfo + /Zope/branches/2.12:109929 Modified: Zope/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py =================================================================== --- Zope/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py 2010-03-12 16:22:28 UTC (rev 109930) +++ Zope/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py 2010-03-12 16:28:15 UTC (rev 109931) @@ -166,12 +166,16 @@ self._settings = {'anonymous_only':1, 'interval':3600, 'notify_urls':()} - self.__cacheid = '%s_%f' % (id(self), time.time()) + self._resetCacheId() def getId(self): ' ' return self.id + security.declarePrivate('_resetCacheId') + def _resetCacheId(self): + self.__cacheid = '%s_%f' % (id(self), time.time()) + security.declarePrivate('ZCacheManager_getCache') def ZCacheManager_getCache(self): cacheid = self.__cacheid Modified: Zope/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py =================================================================== --- Zope/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py 2010-03-12 16:22:28 UTC (rev 109930) +++ Zope/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py 2010-03-12 16:28:15 UTC (rev 109931) @@ -374,12 +374,16 @@ 'request_vars': ('AUTHENTICATED_USER',), 'max_age': 3600, } - self.__cacheid = '%s_%f' % (id(self), time.time()) + self._resetCacheId() def getId(self): ' ' return self.id + security.declarePrivate('_resetCacheId') + def _resetCacheId(self): + self.__cacheid = '%s_%f' % (id(self), time.time()) + ZCacheManager_getCache__roles__ = () def ZCacheManager_getCache(self): cacheid = self.__cacheid Copied: Zope/trunk/src/Products/StandardCacheManagers/configure.zcml (from rev 109929, Zope/branches/2.12/src/Products/StandardCacheManagers/configure.zcml) =================================================================== --- Zope/trunk/src/Products/StandardCacheManagers/configure.zcml (rev 0) +++ Zope/trunk/src/Products/StandardCacheManagers/configure.zcml 2010-03-12 16:28:15 UTC (rev 109931) @@ -0,0 +1,13 @@ +<configure xmlns="http://namespaces.zope.org/zope"> + + <subscriber + for="Products.StandardCacheManagers.RAMCacheManager.RAMCacheManager + OFS.interfaces.IObjectClonedEvent" + handler="Products.StandardCacheManagers.subscribers.cloned" /> + + <subscriber + for="Products.StandardCacheManagers.AcceleratedHTTPCacheManager.AcceleratedHTTPCacheManager + OFS.interfaces.IObjectClonedEvent" + handler="Products.StandardCacheManagers.subscribers.cloned" /> + +</configure> Copied: Zope/trunk/src/Products/StandardCacheManagers/subscribers.py (from rev 109929, Zope/branches/2.12/src/Products/StandardCacheManagers/subscribers.py) =================================================================== --- Zope/trunk/src/Products/StandardCacheManagers/subscribers.py (rev 0) +++ Zope/trunk/src/Products/StandardCacheManagers/subscribers.py 2010-03-12 16:28:15 UTC (rev 109931) @@ -0,0 +1,24 @@ +############################################################################## +# +# Copyright (c) 2010 Zope Foundation 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. +# +############################################################################## +""" subscribers to events affecting StandardCacheManagers +""" + + +def cloned(obj, event): + """ + Reset the Id of the module level cache so the clone gets a different cache + than its source object + """ + obj._resetCacheId() + Copied: Zope/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py (from rev 109929, Zope/branches/2.12/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py) =================================================================== --- Zope/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py (rev 0) +++ Zope/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py 2010-03-12 16:28:15 UTC (rev 109931) @@ -0,0 +1,133 @@ +############################################################################## +# +# Copyright (c) 2010 Zope Foundation 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. +# +############################################################################## +""" Unit tests for AcceleratedCacheManager module. + +$Id$ +""" + +import unittest + +import transaction +import zope.component + +from zope.component import testing as componenttesting +from zope.component import eventtesting + +from AccessControl import SecurityManager +from AccessControl.SecurityManagement import newSecurityManager +from AccessControl.SecurityManagement import noSecurityManager +from OFS.Folder import Folder +from OFS.tests.testCopySupport import CopySupportTestBase +from OFS.tests.testCopySupport import UnitTestSecurityPolicy +from OFS.tests.testCopySupport import UnitTestUser + +from Products.Five import zcml +from Products.StandardCacheManagers.RAMCacheManager import RAMCacheManager +from Products.StandardCacheManagers.AcceleratedHTTPCacheManager \ + import AcceleratedHTTPCacheManager +import Products.StandardCacheManagers + +CACHE_META_TYPES = tuple(dict(name=instance_class.meta_type, + action='unused_constructor_name', + permission="Add %ss" % instance_class.meta_type) + for instance_class in (RAMCacheManager, + AcceleratedHTTPCacheManager) + ) + +class CacheManagerLocationTests(CopySupportTestBase): + + _targetClass = None + + def _makeOne(self, *args, **kw): + return self._targetClass(*args, **kw) + + def setUp( self ): + componenttesting.setUp() + eventtesting.setUp() + zcml.load_config('meta.zcml', zope.component) + zcml.load_config('configure.zcml', Products.StandardCacheManagers) + + folder1, folder2 = self._initFolders() + + folder1.all_meta_types = folder2.all_meta_types = CACHE_META_TYPES + + self.folder1 = folder1 + self.folder2 = folder2 + + self.policy = UnitTestSecurityPolicy() + self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy ) + + cm_id = 'cache' + manager = self._makeOne(cm_id) + self.folder1._setObject(cm_id, manager) + self.cachemanager = self.folder1[cm_id] + transaction.savepoint(optimistic=True) + + newSecurityManager( None, UnitTestUser().__of__( self.root ) ) + + CopySupportTestBase.setUp(self) + + def tearDown( self ): + + noSecurityManager() + SecurityManager.setSecurityPolicy( self.oldPolicy ) + del self.oldPolicy + del self.policy + del self.folder2 + del self.folder1 + + self._cleanApp() + componenttesting.tearDown() + CopySupportTestBase.tearDown(self) + + def test_cache_differs_on_copy(self): + # ensure copies don't hit the same cache + cache = self.cachemanager.ZCacheManager_getCache() + cachemanager_copy = self.folder2.manage_clone(self.cachemanager, + 'cache_copy') + cache_copy = cachemanager_copy.ZCacheManager_getCache() + self.assertNotEqual(cache, cache_copy) + + def test_cache_remains_on_move(self): + # test behaviour of cache on move. + # NOTE: This test verifies current behaviour, but there is no actual + # need for cache managers to maintain the same cache on move. + # if physical path starts being used as a cache key, this test might + # need to be fixed. + cache = self.cachemanager.ZCacheManager_getCache() + cut = self.folder1.manage_cutObjects(['cache']) + self.folder2.manage_pasteObjects(cut) + cachemanager_moved = self.folder2['cache'] + cache_moved = cachemanager_moved.ZCacheManager_getCache() + self.assertEqual(cache, cache_moved) + + # XXX test cache is removed if cachemanager is deleted to prevent leaks? + +class AcceleratedHTTPCacheManagerLocationTests(CacheManagerLocationTests): + + _targetClass = AcceleratedHTTPCacheManager + +class RamCacheManagerLocationTests(CacheManagerLocationTests): + + _targetClass = RAMCacheManager + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(AcceleratedHTTPCacheManagerLocationTests)) + suite.addTest(unittest.makeSuite(RamCacheManagerLocationTests)) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') + _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins