{ "module": "mongo_ops.cache", "content": { "path": "mongo_ops.cache", "docstring": "# Summary\n\nCache backends and configuration for mongo-ops.", "objects": { "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.cache.CacheBackend", "signature": null, "docstring": "Abstract interface for cache backends.\n\nImplementations store byte-encoded values keyed by string, track usage\nstatistics, and manage their own lifecycle. The in-memory and Redis\nbackends both implement this contract.", "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.CacheBackend.get", "signature": "get(key: str)", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.CacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None)", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds. When None, the backend default\n applies." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.CacheBackend.delete", "signature": "delete(key: str)", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.CacheBackend.exists", "signature": "exists(key: str)", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.CacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str)", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.CacheBackend.get_stats", "signature": "get_stats()", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.CacheBackend.initialize", "signature": "initialize()", "docstring": "Start background resources owned by the backend.\n\nShould be called once during application startup, after the\nrepositories are connected." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.CacheBackend.shutdown", "signature": "shutdown()", "docstring": "Stop and release background resources.\n\nShould be called once during application shutdown." } } }, "CacheStats": { "name": "CacheStats", "kind": "class", "path": "mongo_ops.cache.CacheStats", "signature": "CacheStats(hits: int = 0, misses: int = 0, sets: int = 0, deletes: int = 0, current_size: int = 0, max_size: int = 0)", "docstring": "Snapshot of cache usage and activity counters.\n\nAttributes:\n hits (int):\n Number of get() calls that found a value.\n misses (int):\n Number of get() calls that returned None.\n sets (int):\n Number of values written to the cache.\n deletes (int):\n Number of keys removed.\n current_size (int):\n Number of entries currently held.\n max_size (int):\n Maximum number of entries the cache allows (0 = unbounded).", "members": { "hits": { "name": "hits", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.hits", "signature": null, "docstring": null }, "misses": { "name": "misses", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.misses", "signature": null, "docstring": null }, "sets": { "name": "sets", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.sets", "signature": null, "docstring": null }, "deletes": { "name": "deletes", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.deletes", "signature": null, "docstring": null }, "current_size": { "name": "current_size", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.current_size", "signature": null, "docstring": null }, "max_size": { "name": "max_size", "kind": "attribute", "path": "mongo_ops.cache.CacheStats.max_size", "signature": null, "docstring": null } } }, "CircularReferenceError": { "name": "CircularReferenceError", "kind": "class", "path": "mongo_ops.cache.CircularReferenceError", "signature": "CircularReferenceError(collection: str, doc_id: ObjectId, path: list[str])", "docstring": "Raised when population detects a cycle in the reference graph.\n\nAttributes:\n collection (str):\n Collection where the cycle was detected.\n doc_id (ObjectId):\n Document ID where the cycle was detected.\n path (list[str]):\n Ordered labels describing the visited reference path.", "members": { "collection": { "name": "collection", "kind": "attribute", "path": "mongo_ops.cache.CircularReferenceError.collection", "signature": null, "docstring": null }, "doc_id": { "name": "doc_id", "kind": "attribute", "path": "mongo_ops.cache.CircularReferenceError.doc_id", "signature": null, "docstring": null }, "path": { "name": "path", "kind": "attribute", "path": "mongo_ops.cache.CircularReferenceError.path", "signature": null, "docstring": null } } }, "CacheConfig": { "name": "CacheConfig", "kind": "class", "path": "mongo_ops.cache.CacheConfig", "signature": "CacheConfig(enabled: bool = True, backend: Literal['memory', 'redis'] = 'memory', redis_client: Redis | None = None, default_ttl: int = 300, max_entries: int = 10000, key_prefix: str = '', cleanup_interval: int = 60)", "docstring": "Configuration for the cached repository layer.\n\nAttributes:\n enabled (bool):\n Whether caching is active for the repository.\n backend (Literal[\"memory\", \"redis\"]):\n Which backend to use. Defaults to \"memory\".\n redis_client (Optional[Redis]):\n Redis client required when backend is \"redis\".\n default_ttl (int):\n Default time-to-live for cached entries, in seconds.\n max_entries (int):\n Maximum entries for the in-memory backend.\n key_prefix (str):\n Prefix applied to cache keys; defaults to the collection name\n when empty.\n cleanup_interval (int):\n Interval (seconds) for the in-memory expiry sweep.", "members": { "enabled": { "name": "enabled", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.enabled", "signature": null, "docstring": null }, "backend": { "name": "backend", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.backend", "signature": null, "docstring": null }, "redis_client": { "name": "redis_client", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.redis_client", "signature": null, "docstring": null }, "default_ttl": { "name": "default_ttl", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.default_ttl", "signature": null, "docstring": null }, "max_entries": { "name": "max_entries", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.max_entries", "signature": null, "docstring": null }, "key_prefix": { "name": "key_prefix", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.key_prefix", "signature": null, "docstring": null }, "cleanup_interval": { "name": "cleanup_interval", "kind": "attribute", "path": "mongo_ops.cache.CacheConfig.cleanup_interval", "signature": null, "docstring": null } } }, "InMemoryCacheBackend": { "name": "InMemoryCacheBackend", "kind": "class", "path": "mongo_ops.cache.InMemoryCacheBackend", "signature": "InMemoryCacheBackend(max_entries: int = 10000, default_ttl: int = 300, cleanup_interval: int = 60)", "docstring": "Cache backend backed by an in-memory dict with TTL expiry.\n\nEntries are stored in an OrderedDict for LRU-compatible eviction and a\nmin-heap of expiry timestamps drives periodic removal of stale entries.\n\nNotes:\n **Thread safety:**\n\n All operations take an asyncio lock; the backend is safe for\n concurrent use within a single event loop.", "members": { "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.initialize", "signature": "initialize()", "docstring": "Start the periodic expired-entry cleanup task." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.shutdown", "signature": "shutdown()", "docstring": "Cancel and await the cleanup task." }, "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.get", "signature": "get(key: str)", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None)", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds; defaults to the backend default." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.delete", "signature": "delete(key: str)", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.exists", "signature": "exists(key: str)", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str)", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.InMemoryCacheBackend.get_stats", "signature": "get_stats()", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." } } }, "backend": { "name": "backend", "kind": "module", "path": "mongo_ops.cache.backend", "signature": null, "docstring": "# Summary\n\nCache backend abstraction.", "members": { "CacheStats": { "name": "CacheStats", "kind": "class", "path": "mongo_ops.cache.backend.CacheStats", "signature": "CacheStats(hits: int = 0, misses: int = 0, sets: int = 0, deletes: int = 0, current_size: int = 0, max_size: int = 0)", "docstring": "Snapshot of cache usage and activity counters.\n\nAttributes:\n hits (int):\n Number of get() calls that found a value.\n misses (int):\n Number of get() calls that returned None.\n sets (int):\n Number of values written to the cache.\n deletes (int):\n Number of keys removed.\n current_size (int):\n Number of entries currently held.\n max_size (int):\n Maximum number of entries the cache allows (0 = unbounded).", "members": { "hits": { "name": "hits", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.hits", "signature": null, "docstring": null }, "misses": { "name": "misses", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.misses", "signature": null, "docstring": null }, "sets": { "name": "sets", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.sets", "signature": null, "docstring": null }, "deletes": { "name": "deletes", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.deletes", "signature": null, "docstring": null }, "current_size": { "name": "current_size", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.current_size", "signature": null, "docstring": null }, "max_size": { "name": "max_size", "kind": "attribute", "path": "mongo_ops.cache.backend.CacheStats.max_size", "signature": null, "docstring": null } } }, "CircularReferenceError": { "name": "CircularReferenceError", "kind": "class", "path": "mongo_ops.cache.backend.CircularReferenceError", "signature": "CircularReferenceError(collection: str, doc_id: ObjectId, path: list[str])", "docstring": "Raised when population detects a cycle in the reference graph.\n\nAttributes:\n collection (str):\n Collection where the cycle was detected.\n doc_id (ObjectId):\n Document ID where the cycle was detected.\n path (list[str]):\n Ordered labels describing the visited reference path.", "members": { "collection": { "name": "collection", "kind": "attribute", "path": "mongo_ops.cache.backend.CircularReferenceError.collection", "signature": null, "docstring": null }, "doc_id": { "name": "doc_id", "kind": "attribute", "path": "mongo_ops.cache.backend.CircularReferenceError.doc_id", "signature": null, "docstring": null }, "path": { "name": "path", "kind": "attribute", "path": "mongo_ops.cache.backend.CircularReferenceError.path", "signature": null, "docstring": null } } }, "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.cache.backend.CacheBackend", "signature": null, "docstring": "Abstract interface for cache backends.\n\nImplementations store byte-encoded values keyed by string, track usage\nstatistics, and manage their own lifecycle. The in-memory and Redis\nbackends both implement this contract.", "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.get", "signature": "get(key: str) -> bytes | None", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None) -> None", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds. When None, the backend default\n applies." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.delete", "signature": "delete(key: str) -> None", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.exists", "signature": "exists(key: str) -> bool", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str) -> None", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.get_stats", "signature": "get_stats() -> CacheStats", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.initialize", "signature": "initialize() -> None", "docstring": "Start background resources owned by the backend.\n\nShould be called once during application startup, after the\nrepositories are connected." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.backend.CacheBackend.shutdown", "signature": "shutdown() -> None", "docstring": "Stop and release background resources.\n\nShould be called once during application shutdown." } } } } }, "config": { "name": "config", "kind": "module", "path": "mongo_ops.cache.config", "signature": null, "docstring": "# Summary\n\nCache configuration.", "members": { "CacheConfig": { "name": "CacheConfig", "kind": "class", "path": "mongo_ops.cache.config.CacheConfig", "signature": "CacheConfig(enabled: bool = True, backend: Literal['memory', 'redis'] = 'memory', redis_client: Redis | None = None, default_ttl: int = 300, max_entries: int = 10000, key_prefix: str = '', cleanup_interval: int = 60)", "docstring": "Configuration for the cached repository layer.\n\nAttributes:\n enabled (bool):\n Whether caching is active for the repository.\n backend (Literal[\"memory\", \"redis\"]):\n Which backend to use. Defaults to \"memory\".\n redis_client (Optional[Redis]):\n Redis client required when backend is \"redis\".\n default_ttl (int):\n Default time-to-live for cached entries, in seconds.\n max_entries (int):\n Maximum entries for the in-memory backend.\n key_prefix (str):\n Prefix applied to cache keys; defaults to the collection name\n when empty.\n cleanup_interval (int):\n Interval (seconds) for the in-memory expiry sweep.", "members": { "enabled": { "name": "enabled", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.enabled", "signature": null, "docstring": null }, "backend": { "name": "backend", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.backend", "signature": null, "docstring": null }, "redis_client": { "name": "redis_client", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.redis_client", "signature": null, "docstring": null }, "default_ttl": { "name": "default_ttl", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.default_ttl", "signature": null, "docstring": null }, "max_entries": { "name": "max_entries", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.max_entries", "signature": null, "docstring": null }, "key_prefix": { "name": "key_prefix", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.key_prefix", "signature": null, "docstring": null }, "cleanup_interval": { "name": "cleanup_interval", "kind": "attribute", "path": "mongo_ops.cache.config.CacheConfig.cleanup_interval", "signature": null, "docstring": null } } } } }, "in_memory": { "name": "in_memory", "kind": "module", "path": "mongo_ops.cache.in_memory", "signature": null, "docstring": "# Summary\n\nIn-memory cache backend with TTL-based eviction and encode/decode helpers.", "members": { "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.cache.in_memory.CacheBackend", "signature": null, "docstring": "Abstract interface for cache backends.\n\nImplementations store byte-encoded values keyed by string, track usage\nstatistics, and manage their own lifecycle. The in-memory and Redis\nbackends both implement this contract.", "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.get", "signature": "get(key: str)", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None)", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds. When None, the backend default\n applies." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.delete", "signature": "delete(key: str)", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.exists", "signature": "exists(key: str)", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str)", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.get_stats", "signature": "get_stats()", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.initialize", "signature": "initialize()", "docstring": "Start background resources owned by the backend.\n\nShould be called once during application startup, after the\nrepositories are connected." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.in_memory.CacheBackend.shutdown", "signature": "shutdown()", "docstring": "Stop and release background resources.\n\nShould be called once during application shutdown." } } }, "CacheStats": { "name": "CacheStats", "kind": "class", "path": "mongo_ops.cache.in_memory.CacheStats", "signature": "CacheStats(hits: int = 0, misses: int = 0, sets: int = 0, deletes: int = 0, current_size: int = 0, max_size: int = 0)", "docstring": "Snapshot of cache usage and activity counters.\n\nAttributes:\n hits (int):\n Number of get() calls that found a value.\n misses (int):\n Number of get() calls that returned None.\n sets (int):\n Number of values written to the cache.\n deletes (int):\n Number of keys removed.\n current_size (int):\n Number of entries currently held.\n max_size (int):\n Maximum number of entries the cache allows (0 = unbounded).", "members": { "hits": { "name": "hits", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.hits", "signature": null, "docstring": null }, "misses": { "name": "misses", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.misses", "signature": null, "docstring": null }, "sets": { "name": "sets", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.sets", "signature": null, "docstring": null }, "deletes": { "name": "deletes", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.deletes", "signature": null, "docstring": null }, "current_size": { "name": "current_size", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.current_size", "signature": null, "docstring": null }, "max_size": { "name": "max_size", "kind": "attribute", "path": "mongo_ops.cache.in_memory.CacheStats.max_size", "signature": null, "docstring": null } } }, "InMemoryCacheBackend": { "name": "InMemoryCacheBackend", "kind": "class", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend", "signature": "InMemoryCacheBackend(max_entries: int = 10000, default_ttl: int = 300, cleanup_interval: int = 60)", "docstring": "Cache backend backed by an in-memory dict with TTL expiry.\n\nEntries are stored in an OrderedDict for LRU-compatible eviction and a\nmin-heap of expiry timestamps drives periodic removal of stale entries.\n\nNotes:\n **Thread safety:**\n\n All operations take an asyncio lock; the backend is safe for\n concurrent use within a single event loop.", "members": { "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.initialize", "signature": "initialize() -> None", "docstring": "Start the periodic expired-entry cleanup task." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.shutdown", "signature": "shutdown() -> None", "docstring": "Cancel and await the cleanup task." }, "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.get", "signature": "get(key: str) -> bytes | None", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None) -> None", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds; defaults to the backend default." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.delete", "signature": "delete(key: str) -> None", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.exists", "signature": "exists(key: str) -> bool", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str) -> None", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.in_memory.InMemoryCacheBackend.get_stats", "signature": "get_stats() -> CacheStats", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." } } }, "encode_value": { "name": "encode_value", "kind": "function", "path": "mongo_ops.cache.in_memory.encode_value", "signature": "encode_value(value: dict) -> bytes", "docstring": "Encode a dict into cache-ready bytes.\n\nNon-serializable values (e.g., ObjectId) are coerced with str().\n\nArgs:\n value (dict):\n The dictionary to encode.\n\nReturns:\n bytes: UTF-8 JSON bytes." }, "decode_value": { "name": "decode_value", "kind": "function", "path": "mongo_ops.cache.in_memory.decode_value", "signature": "decode_value(data: bytes) -> dict", "docstring": "Decode cache bytes back into a dict.\n\nArgs:\n data (bytes):\n UTF-8 JSON bytes produced by encode_value().\n\nReturns:\n dict: The decoded dictionary." } } }, "redis_backend": { "name": "redis_backend", "kind": "module", "path": "mongo_ops.cache.redis_backend", "signature": null, "docstring": "# Summary\n\nRedis cache backend with key prefixing and pub/sub invalidation.", "members": { "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.cache.redis_backend.CacheBackend", "signature": null, "docstring": "Abstract interface for cache backends.\n\nImplementations store byte-encoded values keyed by string, track usage\nstatistics, and manage their own lifecycle. The in-memory and Redis\nbackends both implement this contract.", "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.get", "signature": "get(key: str)", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None)", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds. When None, the backend default\n applies." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.delete", "signature": "delete(key: str)", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.exists", "signature": "exists(key: str)", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str)", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.get_stats", "signature": "get_stats()", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.initialize", "signature": "initialize()", "docstring": "Start background resources owned by the backend.\n\nShould be called once during application startup, after the\nrepositories are connected." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.redis_backend.CacheBackend.shutdown", "signature": "shutdown()", "docstring": "Stop and release background resources.\n\nShould be called once during application shutdown." } } }, "CacheStats": { "name": "CacheStats", "kind": "class", "path": "mongo_ops.cache.redis_backend.CacheStats", "signature": "CacheStats(hits: int = 0, misses: int = 0, sets: int = 0, deletes: int = 0, current_size: int = 0, max_size: int = 0)", "docstring": "Snapshot of cache usage and activity counters.\n\nAttributes:\n hits (int):\n Number of get() calls that found a value.\n misses (int):\n Number of get() calls that returned None.\n sets (int):\n Number of values written to the cache.\n deletes (int):\n Number of keys removed.\n current_size (int):\n Number of entries currently held.\n max_size (int):\n Maximum number of entries the cache allows (0 = unbounded).", "members": { "hits": { "name": "hits", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.hits", "signature": null, "docstring": null }, "misses": { "name": "misses", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.misses", "signature": null, "docstring": null }, "sets": { "name": "sets", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.sets", "signature": null, "docstring": null }, "deletes": { "name": "deletes", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.deletes", "signature": null, "docstring": null }, "current_size": { "name": "current_size", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.current_size", "signature": null, "docstring": null }, "max_size": { "name": "max_size", "kind": "attribute", "path": "mongo_ops.cache.redis_backend.CacheStats.max_size", "signature": null, "docstring": null } } }, "RedisCacheBackend": { "name": "RedisCacheBackend", "kind": "class", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend", "signature": "RedisCacheBackend(redis_client: Redis, key_prefix: str = '', default_ttl: int = 300)", "docstring": "Cache backend backed by Redis with key prefixing.\n\nValues are stored with a configurable key prefix, and deletions publish\non a shared invalidation channel so other processes can react.\n\nNotes:\n **Lifecycle:**\n\n Requires ``pip install mongo-ops[redis]`` and a live Redis\n connection supplied by the caller.", "members": { "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.initialize", "signature": "initialize() -> None", "docstring": "Open the pub/sub subscription used for invalidation." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.shutdown", "signature": "shutdown() -> None", "docstring": "Close the pub/sub subscription." }, "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.get", "signature": "get(key: str) -> bytes | None", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None) -> None", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds; defaults to the backend default." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.delete", "signature": "delete(key: str) -> None", "docstring": "Remove a key and publish an invalidation notice.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.exists", "signature": "exists(key: str) -> bool", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str) -> None", "docstring": "Remove all keys matching a glob pattern via SCAN/DEL.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.get_stats", "signature": "get_stats() -> CacheStats", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: Stats with current_size taken from Redis dbsize." }, "publish_invalidate": { "name": "publish_invalidate", "kind": "function", "path": "mongo_ops.cache.redis_backend.RedisCacheBackend.publish_invalidate", "signature": "publish_invalidate(key: str) -> None", "docstring": "Publish an invalidation notice for a key.\n\nArgs:\n key (str):\n The cache key to broadcast." } } }, "encode_value": { "name": "encode_value", "kind": "function", "path": "mongo_ops.cache.redis_backend.encode_value", "signature": "encode_value(value: dict) -> bytes", "docstring": "Encode a dict into cache-ready bytes.\n\nNon-serializable values (e.g., ObjectId) are coerced with str().\n\nArgs:\n value (dict):\n The dictionary to encode.\n\nReturns:\n bytes: UTF-8 JSON bytes." }, "decode_value": { "name": "decode_value", "kind": "function", "path": "mongo_ops.cache.redis_backend.decode_value", "signature": "decode_value(data: bytes) -> dict", "docstring": "Decode cache bytes back into a dict.\n\nArgs:\n data (bytes):\n UTF-8 JSON bytes produced by encode_value().\n\nReturns:\n dict: The decoded dictionary." } } }, "repository": { "name": "repository", "kind": "module", "path": "mongo_ops.cache.repository", "signature": null, "docstring": "# Summary\n\nCached repository layer that combines a repository with a cache backend.", "members": { "BaseDocument": { "name": "BaseDocument", "kind": "class", "path": "mongo_ops.cache.repository.BaseDocument", "signature": null, "docstring": "Base document class with common MongoDB fields.\n\nInherit from this class to create Pydantic models that represent\nMongoDB documents. It includes automatic handling of the `_id` field\nand timestamps.\n\nAttributes:\n id: The MongoDB document ID (aliased to `_id`).\n created_at: Timestamp when the document was created.\n updated_at: Timestamp when the document was last updated.", "members": { "id": { "name": "id", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.id", "signature": null, "docstring": null }, "created_at": { "name": "created_at", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.created_at", "signature": null, "docstring": null }, "updated_at": { "name": "updated_at", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.updated_at", "signature": null, "docstring": null }, "Config": { "name": "Config", "kind": "class", "path": "mongo_ops.cache.repository.BaseDocument.Config", "signature": null, "docstring": null, "members": { "populate_by_name": { "name": "populate_by_name", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.Config.populate_by_name", "signature": null, "docstring": null }, "arbitrary_types_allowed": { "name": "arbitrary_types_allowed", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.Config.arbitrary_types_allowed", "signature": null, "docstring": null }, "json_encoders": { "name": "json_encoders", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.Config.json_encoders", "signature": null, "docstring": null }, "json_schema_extra": { "name": "json_schema_extra", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseDocument.Config.json_schema_extra", "signature": null, "docstring": null } } } } }, "BaseRepository": { "name": "BaseRepository", "kind": "class", "path": "mongo_ops.cache.repository.BaseRepository", "signature": "BaseRepository(collection_name: str, model: type[T])", "docstring": "Base repository class combining CRUD operations and collection management.\n\nThis class simplifies repository creation by automatically obtaining the\ndatabase connection and collection instance.\n\nAttributes:\n collection_name: The name of the collection managed by this repository.", "members": { "collection_name": { "name": "collection_name", "kind": "attribute", "path": "mongo_ops.cache.repository.BaseRepository.collection_name", "signature": null, "docstring": null } } }, "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.cache.repository.CacheBackend", "signature": null, "docstring": "Abstract interface for cache backends.\n\nImplementations store byte-encoded values keyed by string, track usage\nstatistics, and manage their own lifecycle. The in-memory and Redis\nbackends both implement this contract.", "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.get", "signature": "get(key: str)", "docstring": "Fetch a value from the cache.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n Optional[bytes]: The cached bytes, or None on a miss." }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.set", "signature": "set(key: str, value: bytes, ttl: int | None = None)", "docstring": "Store a value in the cache.\n\nArgs:\n key (str):\n The cache key.\n value (bytes):\n The byte-encoded value to store.\n ttl (Optional[int]):\n Time-to-live in seconds. When None, the backend default\n applies." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.delete", "signature": "delete(key: str)", "docstring": "Remove a key from the cache.\n\nArgs:\n key (str):\n The cache key." }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.exists", "signature": "exists(key: str)", "docstring": "Check whether a key is present.\n\nArgs:\n key (str):\n The cache key.\n\nReturns:\n bool: True if the key exists, False otherwise." }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.clear_pattern", "signature": "clear_pattern(pattern: str)", "docstring": "Remove all keys matching a glob pattern.\n\nArgs:\n pattern (str):\n Glob-style pattern; a trailing `*` matches prefixes." }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.get_stats", "signature": "get_stats()", "docstring": "Return a snapshot of cache statistics.\n\nReturns:\n CacheStats: A copy of the current stats counters." }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.initialize", "signature": "initialize()", "docstring": "Start background resources owned by the backend.\n\nShould be called once during application startup, after the\nrepositories are connected." }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.cache.repository.CacheBackend.shutdown", "signature": "shutdown()", "docstring": "Stop and release background resources.\n\nShould be called once during application shutdown." } } }, "CacheConfig": { "name": "CacheConfig", "kind": "class", "path": "mongo_ops.cache.repository.CacheConfig", "signature": "CacheConfig(enabled: bool = True, backend: Literal['memory', 'redis'] = 'memory', redis_client: Redis | None = None, default_ttl: int = 300, max_entries: int = 10000, key_prefix: str = '', cleanup_interval: int = 60)", "docstring": "Configuration for the cached repository layer.\n\nAttributes:\n enabled (bool):\n Whether caching is active for the repository.\n backend (Literal[\"memory\", \"redis\"]):\n Which backend to use. Defaults to \"memory\".\n redis_client (Optional[Redis]):\n Redis client required when backend is \"redis\".\n default_ttl (int):\n Default time-to-live for cached entries, in seconds.\n max_entries (int):\n Maximum entries for the in-memory backend.\n key_prefix (str):\n Prefix applied to cache keys; defaults to the collection name\n when empty.\n cleanup_interval (int):\n Interval (seconds) for the in-memory expiry sweep.", "members": { "enabled": { "name": "enabled", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.enabled", "signature": null, "docstring": null }, "backend": { "name": "backend", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.backend", "signature": null, "docstring": null }, "redis_client": { "name": "redis_client", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.redis_client", "signature": null, "docstring": null }, "default_ttl": { "name": "default_ttl", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.default_ttl", "signature": null, "docstring": null }, "max_entries": { "name": "max_entries", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.max_entries", "signature": null, "docstring": null }, "key_prefix": { "name": "key_prefix", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.key_prefix", "signature": null, "docstring": null }, "cleanup_interval": { "name": "cleanup_interval", "kind": "attribute", "path": "mongo_ops.cache.repository.CacheConfig.cleanup_interval", "signature": null, "docstring": null } } }, "decode_value": { "name": "decode_value", "kind": "function", "path": "mongo_ops.cache.repository.decode_value", "signature": "decode_value(data: bytes)", "docstring": "Decode cache bytes back into a dict.\n\nArgs:\n data (bytes):\n UTF-8 JSON bytes produced by encode_value().\n\nReturns:\n dict: The decoded dictionary." }, "encode_value": { "name": "encode_value", "kind": "function", "path": "mongo_ops.cache.repository.encode_value", "signature": "encode_value(value: dict)", "docstring": "Encode a dict into cache-ready bytes.\n\nNon-serializable values (e.g., ObjectId) are coerced with str().\n\nArgs:\n value (dict):\n The dictionary to encode.\n\nReturns:\n bytes: UTF-8 JSON bytes." }, "T": { "name": "T", "kind": "attribute", "path": "mongo_ops.cache.repository.T", "signature": null, "docstring": null }, "CachedBaseRepository": { "name": "CachedBaseRepository", "kind": "class", "path": "mongo_ops.cache.repository.CachedBaseRepository", "signature": "CachedBaseRepository(collection_name: str, model: type[T], cache_backend: CacheBackend, config: CacheConfig | None = None)", "docstring": "Repository that reads and writes through a cache backend.\n\nWraps an existing BaseRepository with an ID-keyed cache. Reads consult\nthe backend first and fall through to MongoDB on a miss, populating the\ncache on success. Writes invalidate or refresh the affected key.\n\nNotes:\n **Guarantees:**\n\n - The cache holds the raw document shape (``model_dump``), so FK\n references round-trip as hex strings, not populated models.\n - When ``config.enabled`` is False the repository behaves exactly\n like its parent with no cache access.", "members": { "get_by_id": { "name": "get_by_id", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.get_by_id", "signature": "get_by_id(id: str | ObjectId) -> T | None", "docstring": "Fetch a document, reading through the cache when enabled.\n\nArgs:\n id (Union[str, ObjectId]):\n The document ID.\n\nReturns:\n Optional[T]: The model instance, or None when not found." }, "create": { "name": "create", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.create", "signature": "create(data: T) -> T", "docstring": "Insert a document and cache the raw snapshot.\n\nArgs:\n data (T):\n The model instance to insert.\n\nReturns:\n T: The created model instance, including its ID." }, "update": { "name": "update", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.update", "signature": "update(id: str | ObjectId, data: dict) -> T | None", "docstring": "Update a document and refresh its cache entry.\n\nArgs:\n id (Union[str, ObjectId]):\n The document ID.\n data (dict):\n Fields to set via $set.\n\nReturns:\n Optional[T]: The updated model instance, or None when not found." }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.delete", "signature": "delete(id: str | ObjectId) -> bool", "docstring": "Delete a document and remove its cache entry.\n\nArgs:\n id (Union[str, ObjectId]):\n The document ID.\n\nReturns:\n bool: True if a document was deleted, False otherwise." }, "warm_cache": { "name": "warm_cache", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.warm_cache", "signature": "warm_cache(ids: list[str | ObjectId]) -> int", "docstring": "Pre-populate the cache for a set of document IDs.\n\nDocs already present in the cache are skipped.\n\nArgs:\n ids (list[Union[str, ObjectId]]):\n Document IDs to warm.\n\nReturns:\n int: Number of entries added to the cache." }, "invalidate_cache": { "name": "invalidate_cache", "kind": "function", "path": "mongo_ops.cache.repository.CachedBaseRepository.invalidate_cache", "signature": "invalidate_cache(id: str | ObjectId) -> None", "docstring": "Remove a single document's cache entry.\n\nArgs:\n id (Union[str, ObjectId]):\n The document ID to invalidate." } } } } } } } }