ahvn.cache.mongo_cache module

MongoDB-based cache backend.

class ahvn.cache.mongo_cache.MongoCache(database=None, collection=None, exclude=None, *args, **kwargs)[源代码]

基类: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).

参数:
__init__(database=None, collection=None, exclude=None, *args, **kwargs)[源代码]

Initialization.

参数:
  • 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__()[源代码]

Get the number of cache entries.

返回:

The number of entries in the cache.

返回类型:

int

close()[源代码]

Close the MongoDB connection.