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]
 
__call__(self, key=None, time_expire=300, cache_model=None)
Decorator function that can be used to cache any function/method.
source code
 
__init__(self, request)
Parameters...
source code
 
action(self, time_expire=300, cache_model=None, prefix=None, session=False, vars=True, lang=True, user_agent=False, public=True, valid_statuses=None, quick=None)
Experimental! Currently only HTTP 1.1 compliant reference : http://code.google.com/p/doctype-mirror/wiki/ArticleHttpCaching time_expire: same as @cache cache_model: same as @cache prefix: add a prefix to the calculated key session: adds response.session_id to the key vars: adds request.env.query_string lang: adds T.accepted_language user_agent: if True, adds is_mobile and is_tablet to the key.
source code

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

Static Methods [hide private]
 
with_prefix(cache_model, prefix)
allow replacing cache.ram with cache.with_prefix(cache.ram,'prefix') it will add prefix to all the cache keys used.
source code
Class Variables [hide private]
  autokey = ':%(name)s:%(args)s:%(vars)s'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__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: "ram", "disk", or other
    (like "memcache" if defined). It defaults to "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
@cache.client instead

__init__(self, request)
(Constructor)

source code 

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

Overrides: object.__init__

action(self, time_expire=300, cache_model=None, prefix=None, session=False, vars=True, lang=True, user_agent=False, public=True, valid_statuses=None, quick=None)

source code 

Experimental!
Currently only HTTP 1.1 compliant
reference : http://code.google.com/p/doctype-mirror/wiki/ArticleHttpCaching
time_expire: same as @cache
cache_model: same as @cache
prefix: add a prefix to the calculated key
session: adds response.session_id to the key
vars: adds request.env.query_string
lang: adds T.accepted_language
user_agent: if True, adds is_mobile and is_tablet to the key.
    Pass a dict to use all the needed values (uses str(.items())) (e.g. user_agent=request.user_agent())
    used only if session is not True
public: if False forces the Cache-Control to be 'private'
valid_statuses: by default only status codes starting with 1,2,3 will be cached.
    pass an explicit list of statuses on which turn the cache on
quick: Session,Vars,Lang,User-agent,Public:
    fast overrides with initial strings, e.g. 'SVLP' or 'VLP', or 'VLP'