[Zope3-dev] ramcache expiration

Marco Andreini m.andreini at tiscali.it
Sun Apr 30 06:03:15 EDT 2006


Hi all,

the zope.app.cache.ram.RAMCache doesn't seem to expire correctly the 
cached data. If I rightly understand the code, the cache for an object 
is expired only when another object is inserted into the cache.

I wrote a little test in order to query only the cache.

---->8---->8---->8----

Set up an object that provide ICacheable and set up a ramcache with the 
max age set to 1 second::

   >>> from zope import interface
   >>> from zope.app.cache.ram import RAMCache
   >>> from zope.app.cache.interfaces import ICacheable

   >>> ramcache = RAMCache()
   >>> ramcache.update(maxEntries=1000, maxAge=1, cleanupInterval=1)

   >>> class CacheableObject(object):
   ...     interface.implements(ICacheable)
   ...     cacheId = None
   ...     def getCacheId(self):
   ...         return cacheId
   ...     def setCacheId(self, cacheId):
   ...         self.cacheId = cacheId

   >>> cacheable = CacheableObject()

Now I query, set and query again the cache and I got the right behavior::

   >>> data = "my data"
   >>> ramcache.query(cacheable) is None
   True
   >>> ramcache.set(data, cacheable)
   >>> ramcache.query(cacheable) is data
   True

Sleep 2 seconds in order to assure the expiration of the cache::

   >>> import time
   >>> time.sleep(2)
   >>> ramcache.query(cacheable) is data
   False

----8<----8<----8<----

With Zope-3.2 I got:

...
Failed example:
     ramcache.query(cacheable) is data
Expected:
     False
Got:
     True

Kind regards,
Marco Andreini


More information about the Zope3-dev mailing list