CacheAdapter

class privex.helpers.cache.CacheAdapter.CacheAdapter(*args, enter_reconnect: Optional[bool] = None, exit_close: Optional[bool] = None, **kwargs)[source]

CacheAdapter is an abstract base class which scaffolds methods for implementing a Cache, allowing for consistent methods and method signatures across all child classes which implement it.

This class cannot be instantiated by itself, only child classes which extend CacheAdapter and implement all methods marked with @abstractmethod can be instantiated.

For an example implementation of CacheAdapter, see privex.helpers.cache.MemoryCache

__init__(*args, enter_reconnect: Optional[bool] = None, exit_close: Optional[bool] = None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

Methods

__init__(*args[, enter_reconnect, exit_close])

Initialize self.

get(key[, default, fail])

Return the value of cache key key.

get_or_set(key, value[, timeout])

Attempt to return the value of key in the cache.

get_or_set_async(key, value[, timeout])

Async coroutine compatible version of get_or_set().

remove(*key)

Remove one or more keys from the cache.

set(key, value[, timeout])

Set the cache key key to the value value, and automatically expire the key after timeout seconds from now.

update_timeout(key[, timeout])

Update the timeout for a given key to datetime.utcnow() + timedelta(seconds=timeout)