def test_update(self): c = RAMCache() c.update(1, 2, 3) s = c._getStorage() self.assertEqual(s.maxEntries, 1, "maxEntries not set") self.assertEqual(s.maxAge, 2, "maxAge not set") self.assertEqual(s.cleanupInterval, 3, "cleanupInterval not set")
def test_timedCleanup(self): from time import sleep c = RAMCache() c.update(cleanupInterval=1, maxAge=2) lastCleanup = c._getStorage().lastCleanup sleep(2) c.set(42, "object", key={'foo': 'bar'}) # last cleanup should now be updated self.failUnless(lastCleanup < c._getStorage().lastCleanup)
from five import grok from itertools import groupby, imap, ifilter from Products.CMFCore.utils import getToolByName from zope.ramcache.ram import RAMCache from seantis.dir.base.interfaces import (IDirectoryItemBase, IDirectoryBase, IDirectoryCatalog) from seantis.dir.base import utils item_cache = RAMCache() item_cache.update(maxAge=0, maxEntries=10000) uncached = object() def directory_cachekey(directory): return ''.join( map(str, (directory.id, directory.modified(), directory.child_modified))) def directory_item_cachekey(directory, item): return directory_cachekey(directory) + str(item.getRID()) def get_object(directory, result): cachekey = directory_item_cachekey(directory, result)
from five import grok from itertools import groupby, imap, ifilter from Products.CMFCore.utils import getToolByName from zope.ramcache.ram import RAMCache from seantis.dir.base.interfaces import ( IDirectoryItemBase, IDirectoryBase, IDirectoryCatalog ) from seantis.dir.base import utils item_cache = RAMCache() item_cache.update(maxAge=0, maxEntries=10000) uncached = object() def directory_cachekey(directory): return ''.join(map(str, ( directory.id, directory.modified(), directory.child_modified ))) def directory_item_cachekey(directory, item): return directory_cachekey(directory) + str(item.getRID())