{ "module": "mongo_ops.cache.redis_backend", "content": { "path": "mongo_ops.cache.redis_backend", "docstring": "# Summary\n\nRedis cache backend with key prefixing and pub/sub invalidation.", "objects": { "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." } } } }