zoom.cache module

zoom.cache - experimental

Provides a cache mechanism that can be used to add automatic caching to functions and methods. Handy for caching generated pages.

Use as a function or method decorator.

zoom.cache.cached(*keys, **kv)

decorator that caches method results

>>> bunch = zoom.utils.Bunch
>>> key = 'x','abc'
>>> db = zoom.database.setup_test('memory')
>>> zoom.system.request = bunch(app=bunch(name='testapp'))
>>> zoom.system.site = bunch(db=db)
>>> class foo(object):
...     def __init__(self, value):
...         self.value = value
...     @cached(key)
...     def get_value(self, param=''):
...         return self.value + param
>>> clear_cache(key)
>>> a = foo('bar')
>>> a.get_value()
'bar'
>>> a.value = 'bahr'
>>> a.get_value()
'bar'
>>> clear_cache('get_value', key)
>>> a.get_value()
'bahr'
zoom.cache.clear_cache(method_name, *keys)

Clear all entries from cache