Skip to main content

Core Module

The core module is the foundation of OmniCache-AI — the central orchestrator, key generation, policies, invalidation, metrics, serialization, compression, stampede protection, cache warming, and multi-tenant namespacing.


Components

ComponentModuleDescription
CacheManageromnicache_ai.core.cache_managerCentral orchestrator — get, set, invalidate, for_tenant()
CacheKeyBuilderomnicache_ai.core.key_buildernamespace:type:sha256[:16] canonical keys
CacheMetricsomnicache_ai.core.metricsHit/miss/eviction counters + provider cache savings
Serializeromnicache_ai.core.serializerPluggable encode/decode — PickleSerializer, JsonSerializer
Compressoromnicache_ai.core.compressorOptional compression — GzipCompressor, NoopCompressor
StampedeShieldomnicache_ai.core.stampedePer-key lock — prevents concurrent duplicate LLM calls
RequestConfigomnicache_ai.core.request_configPer-request TTL / threshold / skip_cache overrides
CacheWarmeromnicache_ai.core.warmerBulk warm from query lists or CSV
TTLPolicyomnicache_ai.core.policiesGlobal + per-layer TTL configuration
EvictionPolicyomnicache_ai.core.policiesLRU / TTL-only strategy
InvalidationEngineomnicache_ai.core.invalidationTag-based bulk eviction
Observabilityomnicache_ai.core.exportersPrometheus + OpenTelemetry exporters
OmnicacheSettingsomnicache_ai.config.settingsUnified config dataclass + from_env()

Architecture


Quick Example

from omnicache_ai import CacheManager, OmnicacheSettings, CacheMetrics

manager = CacheManager.from_settings(OmnicacheSettings.from_env())

key = manager.key_builder.build("response", "my prompt")
manager.set(key, b"cached-result", tags=["model:gpt-4o"])
value = manager.get(key)

# Per-tenant scope
tenant = manager.for_tenant("customer-42")

# Metrics
snap = manager.metrics.snapshot()
print(f"Hit rate: {snap['hit_rate']:.0%}")

# Tag invalidation
manager.invalidate("model:gpt-4o")

Next Steps