Package web2py :: Package gluon :: Module cache :: Class Cache
[hide private]
[frames] | no frames]

Class Cache

source code

object --+
         |
        Cache


Sets up generic caching, creating an instance of both CacheInRam and
CacheOnDisk.
In case of GAE will make use of gluon.contrib.gae_memcache.

- self.ram is an instance of CacheInRam
- self.disk is an instance of CacheOnDisk

Instance Methods [hide private]
 
__init__(self, request)
Parameters...
source code
 
__call__(self, key=None, time_expire=300, cache_model=None)
Decorator function that can be used to cache any function/method.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, request)
(Constructor)

source code 

Parameters
----------
request:
    the global request object

Overrides: object.__init__

__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.