Skip to content

Configuration

The configuration section key is cache. Values are read from YAML, environment variables (QK_CACHE__*), or passed directly to CacheConfig(...).

KeyTypeDefaultEnv VarDescription
enabledboolTrueQK_CACHE__ENABLEDEnable caching
versionstr"1.0.0"QK_CACHE__VERSIONConfig version
environmentstr"development"QK_CACHE__ENVIRONMENTRuntime environment
debugboolFalseQK_CACHE__DEBUGDebug mode
backendslist[CacheBackendConfig][]—Backend configurations
serviceCacheServiceConfig(see below)—Service-level settings

Common fields shared across all backend types:

KeyTypeDefaultEnv VarDescription
namestr(required)—Unique backend identifier
typeBackendType(required)—memory, redis, or memcached
defaultboolFalse—Exactly one backend must be default
enabledboolTrue—Enable this backend
default_ttlintNone—Default TTL in seconds
key_prefixstr""—Key prefix for namespace isolation
KeyTypeDefaultDescription
max_sizeintNoneMax entries before eviction
cleanup_intervalint60Cleanup interval in seconds
enable_metricsboolTrueEnable metrics collection
KeyTypeDefaultEnv VarDescription
redis_hoststr"localhost"QK_CACHE__BACKENDS__0__REDIS_HOSTRedis host
redis_portint6379QK_CACHE__BACKENDS__0__REDIS_PORTRedis port
redis_dbint0QK_CACHE__BACKENDS__0__REDIS_DBRedis database
redis_passwordstrNoneQK_CACHE__BACKENDS__0__REDIS_PASSWORDRedis password
redis_urlstrNoneQK_CACHE__BACKENDS__0__REDIS_URLFull Redis URL
redis_sslboolFalseQK_CACHE__BACKENDS__0__REDIS_SSLEnable SSL/TLS
redis_pool_sizeint10QK_CACHE__BACKENDS__0__REDIS_POOL_SIZEConnection pool size
KeyTypeDefaultEnv VarDescription
memcached_hoststr"localhost"—Memcached host
memcached_portint11211—Memcached port
memcached_serverslist[str]None—Server list (host:port)
KeyTypeDefaultEnv VarDescription
enable_protectionboolTrueQK_CACHE__SERVICE__ENABLE_PROTECTIONStampede protection
enable_metricsboolTrueQK_CACHE__SERVICE__ENABLE_METRICSService-level metrics
enable_health_checksboolTrueQK_CACHE__SERVICE__ENABLE_HEALTH_CHECKSHealth checks
protection_lock_ttlint30QK_CACHE__SERVICE__PROTECTION_LOCK_TTLLock TTL (seconds)
protection_max_waitfloat10.0QK_CACHE__SERVICE__PROTECTION_MAX_WAITMax lock wait
protection_retry_intervalfloat0.1QK_CACHE__SERVICE__PROTECTION_RETRY_INTERVALLock retry interval
default_backendstrNoneQK_CACHE__SERVICE__DEFAULT_BACKENDDefault backend name
circuit_breaker_enabledboolFalseQK_CACHE__SERVICE__CIRCUIT_BREAKER_ENABLEDCircuit breaker
circuit_breaker_thresholdint5QK_CACHE__SERVICE__CIRCUIT_BREAKER_THRESHOLDFailure threshold
default_serializerstr"json"QK_CACHE__SERVICE__DEFAULT_SERIALIZERSerializer type
cache:
backends:
- name: "hot"
type: memory
default: true
max_size: 10000
default_ttl: 300
- name: "persistent"
type: redis
host: "${REDIS_HOST}"
port: 6379
redis_password: "${REDIS_PASSWORD}"
redis_ssl: true
key_prefix: "myapp"
default_ttl: 3600
- name: "fast"
type: memcached
host: "${MEMCACHED_HOST}"
port: 11211
default_ttl: 60
service:
enable_protection: true
protection_lock_ttl: 30
protection_max_wait: 10.0
default_serializer: "json"
Terminal window
# Backend list (indexed by _0_, _1_, etc.)
export QK_CACHE__BACKENDS__0__NAME="hot"
export QK_CACHE__BACKENDS__0__TYPE="memory"
export QK_CACHE__BACKENDS__0__DEFAULT=true
export QK_CACHE__BACKENDS__1__NAME="persistent"
export QK_CACHE__BACKENDS__1__TYPE="redis"
export QK_CACHE__BACKENDS__1__REDIS_HOST="redis.example.com"
export QK_CACHE__BACKENDS__1__REDIS_PORT=6379
export QK_CACHE__BACKENDS__1__REDIS_PASSWORD="${REDIS_PASSWORD}"
# Service settings
export QK_CACHE__SERVICE__ENABLE_PROTECTION=true
export QK_CACHE__SERVICE__DEFAULT_SERIALIZER="json"
# Top-level
export QK_CACHE__ENABLED=true
export QK_CACHE__ENVIRONMENT="production"