aries_cloudagent.cache package

Submodules

aries_cloudagent.cache.base module

Abstract base classes for cache.

class aries_cloudagent.cache.base.BaseCache[source]

Bases: abc.ABC

Abstract cache interface.

acquire(key: str)[source]

Acquire a lock on a given cache key.

abstract async clear(key: str)[source]

Remove an item from the cache, if present.

Parameters

key – the key to remove

abstract async flush()[source]

Remove all items from the cache.

abstract async get(key: str)[source]

Get an item from the cache.

Parameters

key – the key to retrieve an item for

Returns

The record found or None

release(key: str)[source]

Release the lock on a given cache key.

abstract async set(keys: Union[str, Sequence[str]], value: Any, ttl: Optional[int] = None)[source]

Add an item to the cache with an optional ttl.

Parameters
  • keys – the key or keys for which to set an item

  • value – the value to store in the cache

  • ttl – number of second that the record should persist

exception aries_cloudagent.cache.base.CacheError(*args, error_code: Optional[str] = None, **kwargs)[source]

Bases: aries_cloudagent.core.error.BaseError

Base class for cache-related errors.

class aries_cloudagent.cache.base.CacheKeyLock(cache: aries_cloudagent.cache.base.BaseCache, key: str)[source]

Bases: object

A lock on a particular cache key.

Used to prevent multiple async threads from generating or querying the same semi-expensive data. Not thread safe.

property done: bool

Accessor for the done state.

property future: _asyncio.Future

Fetch the result in the form of an awaitable future.

property parent: aries_cloudagent.cache.base.CacheKeyLock

Accessor for the parent key lock, if any.

release()[source]

Release the cache lock.

property result: Any

Fetch the current result, if any.

async set_result(value: Any, ttl: Optional[int] = None)[source]

Set the result, updating the cache and any waiters.

aries_cloudagent.cache.in_memory module

Basic in-memory cache implementation.

class aries_cloudagent.cache.in_memory.InMemoryCache[source]

Bases: aries_cloudagent.cache.base.BaseCache

Basic in-memory cache class.

async clear(key: str)[source]

Remove an item from the cache, if present.

Parameters

key – the key to remove

async flush()[source]

Remove all items from the cache.

async get(key: str)[source]

Get an item from the cache.

Parameters

key – the key to retrieve an item for

Returns

The record found or None

async set(keys: Union[str, Sequence[str]], value: Any, ttl: Optional[int] = None)[source]

Add an item to the cache with an optional ttl.

Overwrites existing cache entries.

Parameters
  • keys – the key or keys for which to set an item

  • value – the value to store in the cache

  • ttl – number of seconds that the record should persist