Skip to content
GitHub

Configuration

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

KeyTypeDefaultEnv VarDescription
enabledboolTrueLEX_CACHE__ENABLEDEnable caching
versionstr"1.0.0"LEX_CACHE__VERSIONConfig version
environmentstr"development"LEX_CACHE__ENVIRONMENTRuntime environment
debugboolFalseLEX_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
defaultboolFalseExactly one backend must be default
enabledboolTrueEnable this backend
default_ttlintNoneDefault TTL in seconds
key_prefixstr""Key prefix for namespace isolation
KeyTypeDefaultDescription
max_sizeintNoneMax entries before eviction
cleanup_intervalint300Cleanup interval in seconds
enable_metricsboolTrueEnable metrics collection
KeyTypeDefaultEnv VarDescription
redis_hoststr"localhost"LEX_CACHE__BACKENDS__0__REDIS_HOSTRedis host
redis_portint6379LEX_CACHE__BACKENDS__0__REDIS_PORTRedis port
redis_dbint0LEX_CACHE__BACKENDS__0__REDIS_DBRedis database
redis_passwordstrNoneLEX_CACHE__BACKENDS__0__REDIS_PASSWORDRedis password
redis_urlstrNoneLEX_CACHE__BACKENDS__0__REDIS_URLFull Redis URL
redis_sslboolFalseLEX_CACHE__BACKENDS__0__REDIS_SSLEnable SSL/TLS
redis_pool_sizeint10LEX_CACHE__BACKENDS__0__REDIS_POOL_SIZEConnection pool size
KeyTypeDefaultEnv VarDescription
memcached_hoststr"localhost"Memcached host
memcached_portint11211Memcached port
memcached_serverslist[str]NoneServer list (host:port)
KeyTypeDefaultEnv VarDescription
enable_protectionboolTrueLEX_CACHE__SERVICE__ENABLE_PROTECTIONStampede protection
enable_metricsboolTrueLEX_CACHE__SERVICE__ENABLE_METRICSService-level metrics
enable_health_checksboolTrueLEX_CACHE__SERVICE__ENABLE_HEALTH_CHECKSHealth checks
protection_lock_ttlint30LEX_CACHE__SERVICE__PROTECTION_LOCK_TTLLock TTL (seconds)
protection_max_waitfloat10.0LEX_CACHE__SERVICE__PROTECTION_MAX_WAITMax lock wait
protection_retry_intervalfloat0.1LEX_CACHE__SERVICE__PROTECTION_RETRY_INTERVALLock retry interval
default_backendstrNoneLEX_CACHE__SERVICE__DEFAULT_BACKENDDefault backend name
circuit_breaker_enabledboolFalseLEX_CACHE__SERVICE__CIRCUIT_BREAKER_ENABLEDCircuit breaker
circuit_breaker_thresholdint5LEX_CACHE__SERVICE__CIRCUIT_BREAKER_THRESHOLDFailure threshold
allow_pickleboolFalseLEX_CACHE__SERVICE__ALLOW_PICKLEAllow pickle serialization
default_serializerstr"json"LEX_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"
allow_pickle: false
Terminal window
# Backend list (indexed by _0_, _1_, etc.)
export LEX_CACHE__BACKENDS__0__NAME="hot"
export LEX_CACHE__BACKENDS__0__TYPE="memory"
export LEX_CACHE__BACKENDS__0__DEFAULT=true
export LEX_CACHE__BACKENDS__1__NAME="persistent"
export LEX_CACHE__BACKENDS__1__TYPE="redis"
export LEX_CACHE__BACKENDS__1__REDIS_HOST="redis.example.com"
export LEX_CACHE__BACKENDS__1__REDIS_PORT=6379
export LEX_CACHE__BACKENDS__1__REDIS_PASSWORD="${REDIS_PASSWORD}"
# Service settings
export LEX_CACHE__SERVICE__ENABLE_PROTECTION=true
export LEX_CACHE__SERVICE__DEFAULT_SERIALIZER="json"
# Top-level
export LEX_CACHE__ENABLED=true
export LEX_CACHE__ENVIRONMENT="production"