cement.core.cache

Cement core cache module.

class cement.core.cache.CementCacheHandler(*args, **kw)

Bases: cement.core.handler.CementBaseHandler

Base class that all Cache Handlers should sub-class from.

class Meta

Bases: object

Handler meta-data (can be passed as keyword arguments to the parent class).

interface

The interface that this handler class implements.

alias of ICache

label = None

String identifier of this handler implementation.

class cement.core.cache.ICache

Bases: cement.core.interface.Interface

This class defines the Cache Handler Interface. Classes that implement this handler must provide the methods and attributes defined below.

Implementations do not subclass from interfaces.

Usage:

from cement.core import cache

class MyCacheHandler(object):
    class Meta:
        interface = cache.ICache
        label = 'my_cache_handler'
    ...
class IMeta

Bases: object

Interface meta-data.

label = 'cache'

The label (or type identifier) of the interface.

validator(klass, obj)

Interface validator function.

_setup(app_obj)

The _setup function is called during application initialization and must ‘setup’ the handler object making it ready for the framework or the application to make further calls to it.

Parameters:app_obj – The application object.
Returns:None
delete(key)

Deletes a key/value from the cache.

Parameters:key – The key in the cache to delete.
Returns:True if the key is successfully deleted, False otherwise.
Return type:boolean
get(key, fallback=None)

Get the value for a key in the cache. If the key does not exist or the key/value in cache is expired, this functions must return ‘fallback’ (which in turn must default to None).

Parameters:
  • key – The key of the value stored in cache
  • fallback – Optional value that is returned if the cache is expired or the key does not exist. Default: None
Returns:

Unknown (whatever the value is in cache, or the fallback)

purge()

Clears all data from the cache.

set(key, value, time=None)

Set the key/value in the cache for a set amount of time.

Parameters:
  • key – The key of the value to store in cache.
  • value – The value of that key to store in cache.
  • time (int (seconds) or None) – A one-off expire time. If no time is given, then a default value is used (determined by the implementation).
Returns:

None

cement.core.cache.cache_validator(klass, obj)

Validates a handler implementation against the ICache interface.