Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
ICache is HexCore’s abstract cache port. Application code depends only on the interface; the concrete backend (in-memory or Redis) is injected through ServerConfig.cache_backend. Swapping from MemoryCache to RedisCache in production requires changing a single line in your config file.
ICache
hexcore.infrastructure.cache.ICache
Abstract base class that all cache backends must implement.
Methods
Retrieves a cached value by key. Returns
None if the key does not exist or has expired.Stores a value under
key. The expire argument is the TTL in seconds; semantics vary by backend (see below).Removes the entry for
key. No-ops silently if the key does not exist.MemoryCache
hexcore.infrastructure.cache.cache_backends.memory.MemoryCache
Simple in-process dictionary cache with no external dependencies. Suitable for development, testing, or single-replica deployments where cache eviction is not required.
Constructor
dict as the backing store.
Methods
| Method | Signature | Notes |
|---|---|---|
get | async (key: str) -> Optional[Dict[str, Any]] | Returns None for missing keys |
set | async (key: str, value: Dict[str, Any], expire: int = 0) -> None | expire is accepted but not enforced — values never expire |
delete | async (key: str) -> None | Silently no-ops for missing keys |
clear | async () -> None | Flushes the entire in-memory store |
MemoryCache does not implement TTL-based expiration. The expire parameter is accepted for interface compatibility but has no effect. Use RedisCache when you need real expiry.RedisCache
hexcore.infrastructure.cache.cache_backends.redis.RedisCache
Production-grade cache backend backed by Redis. Values are JSON-serialised before storage and deserialised on retrieval.
Requires the
hexcore[redis] or hexcore[cache] extra (installs redis[asyncio]):Constructor
LazyConfig.get_config().redis_uri at instantiation time using redis.asyncio.Redis.from_url(..., decode_responses=True).
Configure the URI in your ServerConfig:
config.py
Methods
| Method | Signature | Notes |
|---|---|---|
get | async (key: str) -> Optional[Dict[str, Any]] | Deserialises JSON; returns None for missing/expired keys |
set | async (key: str, value: Dict[str, Any], expire: int = <redis_cache_duration>) -> None | Serialises to JSON; default TTL from ServerConfig.redis_cache_duration (300 s) |
delete | async (key: str) -> None | Issues DEL key |
clear | async () -> None | Issues FLUSHDB — clears the entire Redis database |
Swapping backends
The cache backend is a first-class field onServerConfig. Change it once; every service that uses LazyConfig.get_config().cache_backend picks up the new backend automatically.
- MemoryCache (default)
- RedisCache (production)
- Custom backend
config.py
Using the cache in application code
Always resolve the backend throughLazyConfig so that tests and different environments can inject their own backend: