CacheServiceConfiguration
What it is
Engine configuration models and loader for the Cache service. It supports a stack of cache adapters split into tiers (e.g., hot, cold) and produces a CacheService instance wired with the requested adapters.
Supported adapter types:
fs(filesystem)redis(Redis)object_storage(uses engineObjectStorageService, wired during engine startup)custom(loaded viaGenericLoader)
Public API
Constants
TIER_HOT = "hot"TIER_COLD = "cold"
Configuration models
-
CacheAdapterFSConfiguration- Fields:
base_path: str = "storage/cache" - Extra keys forbidden.
- Fields:
-
CacheAdapterRedisConfiguration- Fields:
redis_url: str,prefix: str,socket_timeout: float | None - Defaults:
redis://localhost:6379/0,naas:cache,None - Extra keys forbidden.
- Fields:
-
CacheAdapterObjectStorageConfiguration- Fields:
cache_prefix: str = "cache" - Extra keys forbidden.
- Fields:
Loader / entry types
CacheAdapterEntry(GenericLoader)- Represents one adapter definition in the cache stack.
- Fields:
adapter: Literal["fs", "redis", "object_storage", "custom"]tier: str = "cold"config: dict | None = None
- Methods:
load_adapter() -> ICacheAdapter- Instantiates the concrete adapter (or delegates to
GenericLoader.load()forcustom).
- Instantiates the concrete adapter (or delegates to
- Validation:
- For non-
custom,configis required and validated against the corresponding pydantic config model.
- For non-
Service configuration
CacheServiceConfiguration(BaseModel)- Fields:
adapters: list[CacheAdapterEntry]- Default: a single
fsadapter incoldtier withbase_path="storage/cache".
- Default: a single
- Methods:
load() -> CacheService- Builds
CacheService(adapters=[(tier, adapter_instance), ...]).
- Builds
- Fields:
Configuration/Dependencies
fsadapter:- Uses
naas_abi_core.services.cache.adapters.secondary.CacheFSAdapter.
- Uses
redisadapter:- Uses
naas_abi_core.services.cache.adapters.secondary.CacheRedisAdapter. - Requires the
redisPython package (as indicated by module docstring).
- Uses
object_storageadapter:- Returns an
ObjectStorageBackedAdapterplaceholder that must be wired later viawire_services(services), which injectsservices.object_storageand creates aCacheObjectStorageAdapter.
- Returns an
Usage
Create a default cache service (filesystem, cold tier)
from naas_abi_core.engine.engine_configuration.EngineConfiguration_CacheService import (
CacheServiceConfiguration,
)
cfg = CacheServiceConfiguration()
cache_service = cfg.load()
Configure Redis (hot) + filesystem (cold)
from naas_abi_core.engine.engine_configuration.EngineConfiguration_CacheService import (
CacheServiceConfiguration,
CacheAdapterEntry,
TIER_HOT,
TIER_COLD,
)
cfg = CacheServiceConfiguration(
adapters=[
CacheAdapterEntry(
adapter="redis",
tier=TIER_HOT,
config={"redis_url": "redis://localhost:6379/0", "prefix": "naas:cache"},
),
CacheAdapterEntry(
adapter="fs",
tier=TIER_COLD,
config={"base_path": "storage/cache"},
),
]
)
cache_service = cfg.load()
Caveats
object_storageadapter is not usable before engine wiring:- Until
wire_services()is called (byCacheService.set_services()during engine startup), calls will raiseRuntimeErrorvia an internal no-op adapter.
- Until
- For
fs,redis, andobject_storage,configmust be provided and must match the respective configuration schema (extra keys are rejected).