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

Class CacheOnDisk

source code

   object --+    
            |    
CacheAbstract --+
                |
               CacheOnDisk

Disk based cache

This is implemented as a shelve object and it is shared by multiple web2py processes (and threads) as long as they share the same filesystem. The file is locked when accessed.

Disk cache provides persistance when web2py is started/stopped but it slower than `CacheInRam`

Values stored in disk cache must be pickable.

Instance Methods [hide private]
 
__call__(self, key, f, time_expire=300)
Tries to retrieve the value corresponding to `key` from the cache if the object exists and if it did not expire, else it calls the function `f` and stores the output in the cache corresponding to `key`.
source code
 
__init__(self, request=None, folder=None)
Initializes the object
source code
 
_close_shelve_and_unlock(self) source code
 
_open_shelve_and_lock(self)
Open and return a shelf object, obtaining an exclusive lock on self.locker first.
source code
 
clear(self, regex=None)
Clears the cache of all keys that match the provided regular expression.
source code
 
increment(self, key, value=1)
Increments the cached value for the given key by the amount in value
source code
 
initialize(self) source code

Inherited from CacheAbstract (private): _clear

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

Class Variables [hide private]

Inherited from CacheAbstract: cache_stats_name

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__call__(self, key, f, time_expire=300)
(Call operator)

source code 

Tries to retrieve the value corresponding to `key` from the cache if the
object exists and if it did not expire, else it calls the function `f`
and stores the output in the cache corresponding to `key`. It always
returns the function that is returned.

Args:
    key(str): the key of the object to be stored or retrieved
    f(function): the function whose output is to be cached.

        If `f` is `None` the cache is cleared.
    time_expire(int): expiration of the cache in seconds.

        It's used to compare the current 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.

Overrides: CacheAbstract.__call__
(inherited documentation)

__init__(self, request=None, folder=None)
(Constructor)

source code 
Initializes the object

Args:
    request: the global request object

Overrides: object.__init__
(inherited documentation)

_open_shelve_and_lock(self)

source code 

Open and return a shelf object, obtaining an exclusive lock on self.locker first. Replaces the close method of the returned shelf instance with one that releases the lock upon closing.

clear(self, regex=None)

source code 

Clears the cache of all keys that match the provided regular expression.
If no regular expression is provided, it clears all entries in cache.

Args:
    regex: if provided, only keys matching the regex will be cleared,
        otherwise all keys are cleared.

Overrides: CacheAbstract.clear
(inherited documentation)

increment(self, key, value=1)

source code 

Increments the cached value for the given key by the amount in value

Args:
    key(str): key for the cached object to be incremeneted
    value(int): amount of the increment (defaults to 1, can be negative)

Overrides: CacheAbstract.increment
(inherited documentation)