AsyncCacheAdapter

class privex.helpers.cache.asyncx.base.AsyncCacheAdapter(*args, **kwargs)[source]

AsyncCacheAdapter is an abstract base class based on CacheAdapter, but with all methods designated as coroutines.

Cache adapters which make use of AsyncIO, including via asyncio compatible libraries (e.g. aioredis), should use this class as their parent instead of CacheAdapter.

To retain the functionality of __getitem__() and __setitem__(), it obtains an event loop using asyncio.get_event_loop(), and then wraps get() or set() respectively using loop.run_until_complete to be able to run them within the synchronous get/setitem magic methods.

It overrides get_or_set() to convert it into an async method, and overrides get_or_set_async() so that get() and set() are correctly awaited within the method.

__init__(*args, **kwargs)

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

Methods

Methods

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)