Quick search

Table Of Contents

Cache manager

The cache manager can be used to store python object attached to an uniq key. The cache can be controlled in different manner, with a object limit or a timeout.

For example, we can create a new cache with a limit of 10 objects and a timeout of 5 seconds:

# register a new Cache
Cache.register('mycache', limit=10, timeout=5)

# create an object + id
text = 'objectid'
instance = Label(text=text)
Cache.append('mycache', text, instance)

# retrieve the cached object
instance = Cache.get('mycache', label)

If the instance is NULL, the cache may have trash it, because you’ve not used the label since 5 seconds, and you’ve reach the limit.

class kivy.cache.Cache

Bases: object

See module documentation for more information.

static append(category, key, obj, timeout=None)

Add a new object in the cache.

Parameters :
category : str

Identifier of the category

key : str

Uniq identifier of the object to store

obj : object

Object to store in cache

timeout : double (optionnal)

Custom time to delete the object if it’s not used.

static get(category, key, default=None)

Get a object in cache.

Parameters :
category : str

Identifier of the category

key : str

Uniq identifier of the object to store

default : anything, default to None

Default value to be returned if key is not found

static get_lastaccess(category, key, default=None)

Get the object last access time in cache.

Parameters :
category : str

Identifier of the category

key : str

Uniq identifier of the object to store

default : anything, default to None

Default value to be returned if key is not found

static get_timestamp(category, key, default=None)

Get the object timestamp in cache.

Parameters :
category : str

Identifier of the category

key : str

Uniq identifier of the object to store

default : anything, default to None

Default value to be returned if key is not found

static print_usage()

Print the cache usage on the console

static register(category, limit=None, timeout=None)

Register a new category in cache, with limit

Parameters :
category : str

Identifier of the category

limit : int (optionnal)

Maximum number of object in the cache. If None, no limit is applied.

timeout : double (optionnal)

Time to delete the object when it’s not used. if None, no timeout is applied.

static remove(category, key=None)

Purge the cache

Parameters :
category : str (optionnal)

Identifier of the category

key : str (optionnal)

Uniq identifier of the object to store