[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/cache/ Fixed a cleanup bug reported, fixed and tested by Zhiyun (Simon) Hang.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jan 3 13:44:17 EST 2006


Log message for revision 41108:
  Fixed a cleanup bug reported, fixed and tested by Zhiyun (Simon) Hang.
  

Changed:
  U   Zope3/trunk/src/zope/app/cache/ram.py
  U   Zope3/trunk/src/zope/app/cache/tests/test_ramcache.py

-=-
Modified: Zope3/trunk/src/zope/app/cache/ram.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/ram.py	2006-01-03 18:37:08 UTC (rev 41107)
+++ Zope3/trunk/src/zope/app/cache/ram.py	2006-01-03 18:44:17 UTC (rev 41108)
@@ -180,6 +180,10 @@
             self.cleanupInterval = cleanupInterval
 
     def getEntry(self, ob, key):
+
+        if self.lastCleanup <= time() - self.cleanupInterval:
+            self.cleanup()
+
         try:
             data = self._data[ob][key]
         except KeyError:

Modified: Zope3/trunk/src/zope/app/cache/tests/test_ramcache.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/tests/test_ramcache.py	2006-01-03 18:37:08 UTC (rev 41107)
+++ Zope3/trunk/src/zope/app/cache/tests/test_ramcache.py	2006-01-03 18:44:17 UTC (rev 41108)
@@ -238,6 +238,21 @@
             raise "ExpectedKeyError"
         self.assertEqual(s._misses[object2], 1)
 
+    def test_getEntry_do_cleanup(self):
+         from zope.app.cache.ram import Storage
+
+         s = Storage(cleanupInterval=300, maxAge=300)
+         object = 'object'
+         key = ('view', (), ('answer', 42))
+         value = 'yes'
+
+         s.setEntry(object, key, value)
+
+         s._data[object][key][1] = time() - 400
+         s.lastCleanup = time() - 400
+
+         self.assertRaises(KeyError, s.getEntry, object, key)
+
     def test_setEntry(self):
         from zope.app.cache.ram import Storage
 



More information about the Zope3-Checkins mailing list