__call__(self,
key=None,
time_expire=300,
cache_model=None)
(Call operator)
| source code
|
Decorator function that can be used to cache any function/method.
Example::
@cache('key', 5000, cache.ram)
def f():
return time.ctime()
When the function f is called, web2py tries to retrieve
the value corresponding to `key` from the cache of the
object exists and if it did not expire, else it calles the function `f`
and stores the output in the cache corresponding to `key`. In the case
the output of the function is returned.
:param key: the key of the object to be store or retrieved
:param time_expire: expiration of the cache in microseconds
:param cache_model: `cache.ram`, `cache.disk`, or other
(like `cache.memcache` if defined). It defaults to `cache.ram`.
Notes
-----
`time_expire` is used to compare the curret time with the time when the
requested object was last saved in cache. It does not affect future
requests.
Setting `time_expire` to 0 or negative value forces the cache to
refresh.
If the function `f` is an action, we suggest using
`request.env.path_info` as key.
|