async_cached

privex.helpers.cache.async_cached: Union[privex.helpers.cache.asyncx.base.AsyncCacheAdapter, privex.helpers.cache.AsyncCacheWrapper] = <privex.helpers.cache.AsyncCacheWrapper object>

For applications/packages which are primarily AsyncIO, CacheWrapper can cause problems such as the common event loop is already running - and unfortunately, nest_asyncio isn’t always able to fix it.

This wrapper - AsyncCacheWrapper is ONLY compatible with AsyncIO code, and holds a different adapter instance in cache_instance than CacheWrapper, as it expects the adapter instance to always be based on AsyncCacheAdapter - along with the fact it generally returns coroutines.

>>> from privex.helpers.cache import async_cached, async_adapter_set, AsyncRedisCache
>>> async_adapter_set(AsyncRedisCache())
>>> c = async_cached      # We alias async_cached to 'c' for convenience.
>>> c['hello'] = 'world'  # We can set cache keys as if the wrapper was a dictionary
>>> c['hello']            # Similarly we can also get keys like normal
'world'
>>> await c['hello']      # It's safest to use ``await`` when getting keys within an async context
'world'
>>> await c.get('hello')  # We can also use the coroutines .get, .set, .get_or_set etc.
'world'