Skip to content

Config

mongo_ops.cache.config

Summary

Cache configuration.

Classes

CacheConfig dataclass

1
2
3
4
5
6
7
8
9
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,
)

Configuration for the cached repository layer.

Attributes:

Name Type Description
enabled bool

Whether caching is active for the repository.

backend Literal['memory', 'redis']

Which backend to use. Defaults to "memory".

redis_client Optional[Redis]

Redis client required when backend is "redis".

default_ttl int

Default time-to-live for cached entries, in seconds.

max_entries int

Maximum entries for the in-memory backend.

key_prefix str

Prefix applied to cache keys; defaults to the collection name when empty.

cleanup_interval int

Interval (seconds) for the in-memory expiry sweep.

Functions
__post_init__
__post_init__() -> None

Validate backend/redis consistency.

Raises:

Type Description
ValueError

If the backend is "redis" and no client is given.

ImportError

If the redis package is not installed.