Skip to content
GitHub

Lexigram-Cache API

Lexigram Cache - Multi-backend caching system for Lexigram Framework.

Section titled “Lexigram Cache - Multi-backend caching system for Lexigram Framework.”
  • def getattr(name: str) -> Any

  • def dir() -> Any

Admin contributor for lexigram-cache — surfaces cache hit/miss, eviction,

Section titled “Admin contributor for lexigram-cache — surfaces cache hit/miss, eviction,”

Shared Jinja2 renderer for lexigram-cache admin widgets.

Section titled “Shared Jinja2 renderer for lexigram-cache admin widgets.”

Frozen view models for lexigram-cache admin widgets.

Section titled “Frozen view models for lexigram-cache admin widgets.”

Backend factory helpers for Lexigram Cache provider.

Section titled “Backend factory helpers for Lexigram Cache provider.”

Memory cache backend implementation using lexigram-components.

Section titled “Memory cache backend implementation using lexigram-components.”

In-memory storage implementation for Lexigram.

Section titled “In-memory storage implementation for Lexigram.”
  • class InMemoryStorage:

    Namespace-aware in-memory storage backend backed by MemoryStateStore.

    Section titled “Namespace-aware in-memory storage backend backed by MemoryStateStore.”
    init(self, max_size: int = 10000, default_ttl: int | None = None, cleanup_interval: int = 60) -> None
    • def init(self, max_size: int = 10000, default_ttl: int | None = None, cleanup_interval: int = 60) ->
    • @property
    • def storage_type(self) -> StorageType
    • async def connect(self) -> None
    • async def disconnect(self) -> None
    • async def get(self, key: str, namespace: str | None = None) -> Any | None
    • async def set(self, key: str, value: Any, namespace: str | None = None, ttl: int | None = None) -> bool
    • async def delete(self, key: str, namespace: str | None = None) -> bool
    • async def exists(self, key: str, namespace: str | None = None) -> bool
    • async def list_keys(self, pattern: str | None = None, namespace: str | None = None) -> list[str]
    • async def clear(self, namespace: str | None = None) -> bool
    • async def _periodic_cleanup(self) -> None
    • async def _cleanup_expired(self) -> None

Redis cache backend implementation using the centralized StateStoreProtocol protocol.

Section titled “Redis cache backend implementation using the centralized StateStoreProtocol protocol.”

Local circuit breaker backend types for lexigram-cache.

Section titled “Local circuit breaker backend types for lexigram-cache.”

Resilience backends for the Lexigram cache package.

Section titled “Resilience backends for the Lexigram cache package.”

Resilient Redis cache backend — decorator composition (D3.3).

Section titled “Resilient Redis cache backend — decorator composition (D3.3).”

Cache backend registry for extensible cache backends.

Section titled “Cache backend registry for extensible cache backends.”

Cache repository generator for creating cached data repositories.

Section titled “Cache repository generator for creating cached data repositories.”

CLI shell context factories for lexigram-cache.

Section titled “CLI shell context factories for lexigram-cache.”
  • global ENV_PREFIX: str = ‘LEX_CACHE__’

  • global ENV_NESTED_DELIMITER: str = ’__’

  • global ENV_VAR_LEX_ENV: str = ‘LEX_ENV’

  • global DEFAULT_CACHE_NAME: str = ‘cache’

  • global DEFAULT_CACHE_VERSION: str = ‘1.0.0’

  • global DEFAULT_CACHE_ENABLED: bool = True

  • global DEFAULT_CACHE_ENVIRONMENT: str = ‘development’

  • global DEFAULT_CACHE_DEBUG: bool = False

  • global DEFAULT_SERVICE_PROTECTION_ENABLED: bool = True

  • global DEFAULT_SERVICE_METRICS_ENABLED: bool = True

  • global DEFAULT_SERVICE_HEALTH_CHECKS_ENABLED: bool = True

  • global DEFAULT_SERVICE_CIRCUIT_BREAKER_ENABLED: bool = False

  • global DEFAULT_SERVICE_CIRCUIT_BREAKER_THRESHOLD: int = 5

  • global DEFAULT_SERVICE_SERIALIZER: str = ‘json’

  • global DEFAULT_SERVICE_ALLOW_PICKLE: bool = False

  • global DEFAULT_PROTECTION_LOCK_TTL: int = 30

  • global DEFAULT_PROTECTION_MAX_WAIT: float = 10.0

  • global DEFAULT_PROTECTION_RETRY_INTERVAL: float = 0.1

  • global DEFAULT_MEMORY_NAME: str = ‘memory’

  • global DEFAULT_MEMORY_ENABLED: bool = True

  • global DEFAULT_MEMORY_DEFAULT: bool = False

  • global DEFAULT_MEMORY_CLEANUP_INTERVAL: int = 60

  • global DEFAULT_REDIS_NAME: str = ‘redis’

  • global DEFAULT_REDIS_HOST: str = ‘localhost’

  • global DEFAULT_REDIS_PORT: int = 6379

  • global DEFAULT_REDIS_DB: int = 0

  • global DEFAULT_REDIS_ENABLED: bool = True

  • global DEFAULT_REDIS_DEFAULT: bool = False

  • global DEFAULT_REDIS_SSL: bool = False

  • global DEFAULT_REDIS_CONNECTION_POOL_SIZE: int = 10

  • global DEFAULT_REDIS_SOCKET_TIMEOUT: float = 5.0

  • global DEFAULT_REDIS_RETRY_ON_TIMEOUT: bool = True

  • global DEFAULT_MEMCACHED_NAME: str = ‘memcached’

  • global DEFAULT_MEMCACHED_HOST: str = ‘localhost’

  • global DEFAULT_MEMCACHED_PORT: int = 11211

  • global DEFAULT_MEMCACHED_ENABLED: bool = True

  • global DEFAULT_MEMCACHED_DEFAULT: bool = False

  • global DEFAULT_LOCK_KEY_PREFIX: str = ‘lock:’

  • global DEFAULT_LOCK_TTL: int = 30

  • global DEFAULT_LOCK_RENEWAL_INTERVAL_DIVISOR: int = 2

  • global COMPRESSION_MARKER_UNCOMPRESSED: bytes = b’\x00’

  • global COMPRESSION_MARKER_COMPRESSED: bytes = b’\x01’

  • global DEFAULT_COMPRESSION_THRESHOLD: int = 1024

  • global DEFAULT_COMPRESSION_LEVEL: int = 6

  • global INSECURE_PASSWORDS: tuple[str, …]

  • global BACKEND_TYPE_MEMORY: str = ‘memory’

  • global BACKEND_TYPE_REDIS: str = ‘redis’

  • global BACKEND_TYPE_MEMCACHED: str = ‘memcached’

  • global CACHE_STATUS_HIT: str = ‘hit’

  • global CACHE_STATUS_MISS: str = ‘miss’

  • global CACHE_STATUS_SET: str = ‘set’

  • global CACHE_STATUS_DELETE: str = ‘delete’

  • global CACHE_STATUS_ERROR: str = ‘error’

  • global CACHE_STATUS_EXPIRED: str = ‘expired’

  • global CACHE_STATUS_STALE: str = ‘stale’

  • global ERROR_MSG_CACHE_TIMEOUT: str = ‘Cache operation timed out’

  • global ERROR_MSG_CACHE_CONFIGURATION: str = ‘Cache configuration error’

  • global ERROR_MSG_CACHE_STAMPEDE: str = ‘Cache stampede protection error’

  • global ERROR_MSG_CACHE_INVALIDATION: str = ‘Cache invalidation failed’

  • global ERROR_MSG_REDIS_INSTALL: str = ‘Redis backend requires redis package. Install with: pip install lexigram-cache[redis]’

  • global ERROR_MSG_MEMCACHED_INSTALL: str = ‘Memcached backend requires pylibmc or python-memcached. Install with: pip install lexigram-cache[memcached]’

  • global ERROR_MSG_PYYAML_INSTALL: str = ‘PyYAML is required for YAML configuration loading’

  • global ERROR_MSG_INSECURE_PASSWORD: str = “CRITICAL SECURITY ERROR: Insecure {backend} password detected in PRODUCTION for backend ‘{name}’.\nYou MUST set a secure password via {env_var}.”

  • global ERROR_MSG_INSECURE_URL: str = “CRITICAL SECURITY ERROR: Insecure {backend} URL detected in PRODUCTION for backend ‘{name}’.\nYou MUST set a secure {backend} URL via {env_var}.”

  • global DEFAULT_ENCODING: str = ‘utf-8’

Integration layer for Lexigram Cache provider.

Section titled “Integration layer for Lexigram Cache provider.”
  • global T

Root hook payload surface for lexigram-cache.

Section titled “Root hook payload surface for lexigram-cache.”
  • class LockContextManager:

    Async context manager for distributed locks.

    Section titled “Async context manager for distributed locks.”
    init(self, redis: Any, key: str, ttl: int, auto_renew: bool) -> None
    • def init(self, redis: Any, key: str, ttl: int, auto_renew: bool) -> None
    • async def aenter(self) -> AutoRenewingLock
    • async def aexit(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: object) -> None

Distributed lock with automatic TTL renewal.

Section titled “Distributed lock with automatic TTL renewal.”

RepositoryProtocol pattern implementations for Lexigram Cache.

Section titled “RepositoryProtocol pattern implementations for Lexigram Cache.”

Semantic cache for LLM response caching with vector similarity search.

Section titled “Semantic cache for LLM response caching with vector similarity search.”
  • def getattr(name: str) -> Any

  • def dir() -> Any

Cost-aware semantic cache hit decision logic.

Section titled “Cost-aware semantic cache hit decision logic.”

Internal protocols for semantic cache vector indexing.

Section titled “Internal protocols for semantic cache vector indexing.”

Three-tier semantic cache store for LLM response caching.

Section titled “Three-tier semantic cache store for LLM response caching.”

FAISS-backed vector index for semantic cache.

Section titled “FAISS-backed vector index for semantic cache.”

Serialization abstraction layer for Lexigram Cache.

Section titled “Serialization abstraction layer for Lexigram Cache.”

Cache serializer with automatic compression for large values.

Section titled “Cache serializer with automatic compression for large values.”

AsyncStringSerializerProtocol helpers for provider initialization.

Section titled “AsyncStringSerializerProtocol helpers for provider initialization.”

JSON-based serializer implementation for Lexigram Cache.

Section titled “JSON-based serializer implementation for Lexigram Cache.”

MessagePack serializer for Lexigram Cache.

Section titled “MessagePack serializer for Lexigram Cache.”

HMAC-signed pickle serializer for Lexigram Cache.

Section titled “HMAC-signed pickle serializer for Lexigram Cache.”

Core cache service implementation for Lexigram Framework.

Section titled “Core cache service implementation for Lexigram Framework.”

Caching decorators for Lexigram Framework.

Section titled “Caching decorators for Lexigram Framework.”

Service factory helpers for provider initialization.

Section titled “Service factory helpers for provider initialization.”

Health and metrics helpers for the Lexigram cache provider.

Section titled “Health and metrics helpers for the Lexigram cache provider.”

Cache-aside, write-through, and stampede-protected pattern mixin.

Section titled “Cache-aside, write-through, and stampede-protected pattern mixin.”

Cache status handler registry for metrics collection.

Section titled “Cache status handler registry for metrics collection.”

Request-scoped in-process cache backed by :mod:contextvars.

Section titled “Request-scoped in-process cache backed by :mod:contextvars.”

Stampede protection utilities extracted from protection.py.

Section titled “Stampede protection utilities extracted from protection.py.”

CacheWarmer — proactive cache pre-loading at boot or on schedule (D6.4).

Section titled “CacheWarmer — proactive cache pre-loading at boot or on schedule (D6.4).”

Tiered caching strategy for Lexigram Cache.

Section titled “Tiered caching strategy for Lexigram Cache.”

Write-through caching strategy for Lexigram Cache.

Section titled “Write-through caching strategy for Lexigram Cache.”