mentat.services.cache module

class mentat.services.cache.CacheService(path, name, timeout=None, to_force=False, bsize=16777216, purge_int=15)[source]

Bases: object

Imlementation of the cache dictionary

GLOB_DB_NAME = 'global.db'
clear()[source]

Empty a database

Returns

None

get(key, default=None)[source]

Get a value stored in the cache for a given key

If the record has expired, the default value is returned. :param key: The key to be search in the cache :param default: Value to return if the record is not present. :return: The value or default

purge()[source]

Remove expired records from the cache

First, the function prepare a set of timestamps to remove and then it will remove them. This prevents the process to hold a write cursor for long time and block other processes during cache purge. :return: None

set(key, value, timeout=None)[source]

Store a key/value pair to the cache

If the key already exists in the cache, the previous value is replaced. The key and value must be pickable objects.

Parameters
  • key – The key to be used

  • value – The value to be stored

  • timeout (int) – Override default timeout value (seconds)

Returns

None

exception mentat.services.cache.CacheServiceError[source]

Bases: BaseException

Custom cache exception

class mentat.services.cache.CacheServiceManager(core_config, updates=None)[source]

Bases: object

Class representing a custom CacheManager capable of understanding and parsing Mentat system core configuration and enabling easy bootstrapping of mentat.services.cache.CacheService.

cache(name, timeout=None, to_force=False)[source]

Return handle to a cache according to internal configuration and user defined parameters

For a detailed description of parameters, see mentat.services.cache.CacheService . :param str name: Name of the cache to create/load :param int timeout: Default record timeout (seconds) or None :param bool to_force: Overwrite current timeout, if defined :return: Reference to the cache object :rtype: mentat.services.cache.CacheService