4.1. foundations.cache

cache.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines caching related classes.

Others:

4.1.1. Module Attributes

foundations.cache.LOGGER

4.1.2. Classes

class foundations.cache.Cache(**kwargs)[source]

Bases: dict

Defines the cache object and provides various methods to interact with its content.

Usage:

Initializes the class.

Parameters:**kwargs (dict) – Key / Value pairs.
addContent(**content)[source]

Adds given content to the cache.

Usage:

>>> cache = Cache()
>>> cache.addContent(John="Doe", Luke="Skywalker")
True
>>> cache
{'Luke': 'Skywalker', 'John': 'Doe'}
Parameters:**content (**) – Content to add.
Returns:Method success.
Return type:bool
removeContent(*keys)[source]

Removes given content from the cache.

Usage:

>>> cache = Cache()
>>> cache.addContent(John="Doe", Luke="Skywalker")
True
>>> cache.removeContent("Luke", "John")
True
>>> cache
{}                      
Parameters:*keys (*) – Content to remove.
Returns:Method success.
Return type:bool
getContent(key)[source]

Gets given content from the cache.

Usage:

>>> cache = Cache()
>>> cache.addContent(John="Doe", Luke="Skywalker")
True
>>> cache.getContent("Luke")
'Skywalker'
Parameters:key (object) – Content to retrieve.
Returns:Content.
Return type:object
flushContent()[source]

Flushes the cache content.

Usage:

>>> cache = Cache()
>>> cache.addContent(John="Doe", Luke="Skywalker")
True
>>> cache.flushContent()
True
>>> cache
{}
Returns:Method success.
Return type:bool