[Zope3-checkins] SVN: Zope3/branches/3.3/ Fixed zope.app.cache.ram.RAMCache which ignored the cleanupInterval

Bernd Dorn bernd.dorn at lovelysystems.com
Mon Mar 5 08:11:11 EST 2007


Log message for revision 72988:
  Fixed zope.app.cache.ram.RAMCache which ignored the cleanupInterval

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/app/cache/ram.py
  U   Zope3/branches/3.3/src/zope/app/cache/tests/test_ramcache.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2007-03-05 13:10:41 UTC (rev 72987)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2007-03-05 13:11:10 UTC (rev 72988)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed zope.app.cache.ram.RAMCache which ignored the
+        cleanupinterval.
+
       - zope.testing: moved import of the pystone module due a import
         conflict with the Zope 2 testrunner
         (http://www.zope.org/Collectors/Zope/2268)

Modified: Zope3/branches/3.3/src/zope/app/cache/ram.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/cache/ram.py	2007-03-05 13:10:41 UTC (rev 72987)
+++ Zope3/branches/3.3/src/zope/app/cache/ram.py	2007-03-05 13:11:10 UTC (rev 72988)
@@ -286,6 +286,7 @@
         "Cleanup the data"
         self.removeStaleEntries()
         self.removeLeastAccessed()
+        self.lastCleanup = time()
 
     def removeLeastAccessed(self):
         ""
@@ -338,7 +339,7 @@
             hits = sum(entry[2] for entry in self._data[ob].itervalues())
             result.append({'path': ob,
                            'hits': hits,
-                           'misses': self._misses[ob],
+                           'misses': self._misses.get(ob, 0),
                            'size': size,
                            'entries': len(self._data[ob])})
         return tuple(result)

Modified: Zope3/branches/3.3/src/zope/app/cache/tests/test_ramcache.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/cache/tests/test_ramcache.py	2007-03-05 13:10:41 UTC (rev 72987)
+++ Zope3/branches/3.3/src/zope/app/cache/tests/test_ramcache.py	2007-03-05 13:11:10 UTC (rev 72988)
@@ -87,6 +87,17 @@
         self.assertEqual(s.maxAge, 2, "maxAge not set")
         self.assertEqual(s.cleanupInterval, 3, "cleanupInterval not set")
 
+    def test_timedCleanup(self):
+        from zope.app.cache.ram import RAMCache
+        import time
+        c = RAMCache()
+        c.update(cleanupInterval=1, maxAge=2)
+        lastCleanup = c._getStorage().lastCleanup
+        time.sleep(2)
+        c.set(42, "object", key={'foo': 'bar'})
+        # last cleanup should now be updated
+        self.failUnless(lastCleanup < c._getStorage().lastCleanup)
+
     def test_cache(self):
         from zope.app.cache import ram
         self.assertEqual(type(ram.caches), type({}),



More information about the Zope3-Checkins mailing list