ahvn.cache.mongo_cache module¶

MongoDB-based cache backend.

class ahvn.cache.mongo_cache.MongoCache(database=None, collection=None, exclude=None, *args, **kwargs)[source]¶

Bases: BaseCache

An implementation of BaseCache that stores data in a MongoDB collection. Each cache entry is stored as a document with an integer _id (cache key) and a content field (JSON data).

Parameters:
__init__(database=None, collection=None, exclude=None, *args, **kwargs)[source]¶

Initialization.

Parameters:
  • database (Optional[str]) – MongoDB database name.

  • collection (Optional[str]) – MongoDB collection name for cache storage.

  • exclude (Optional[Iterable[str]]) – Keys to exclude from inputs when creating cache entries.

  • *args – Additional positional arguments.

  • **kwargs – Additional keyword arguments for MongoDB connection.

__len__()[source]¶

Get the number of cache entries.

Returns:

The number of entries in the cache.

Return type:

int

close()[source]¶

Close the MongoDB connection.