Cache configuration is defined in cache/config.Config:
cache:
kind: redis
compressor: zstd
encoder: json
max_size: 4MB
max_entries: 1024
options:
url: env:CACHE_URL
[!NOTE]
- Built-in driver kinds in this repo are
redisandttlcache.- Unknown
kindvalues returncache/driver/errors.ErrNotFound.- Unknown or empty
compressorvalues fall back tonone.- For normal values, unknown or empty
encodervalues fall back tojson.- Configured
compressorandencodervalues are part of the cache driver key namespace, so changing either setting creates cache misses for values written with the previous format.- Cache operations use
bytesforio.WriterTo/io.ReaderFromstream values andprotobuffor protobuf messages, regardless of the configuredencoder.max_sizelimits encoded cache values before compression, after compression, and after decompression. A zero value uses the default4MB.max_entrieslimits entries retained by bounded in-memory cache drivers. A zero value uses the default1024; negative values are invalid.optionsis backend-specific and decoded asmap[string]any.- Redis-backed
GetOrPersistrequires Redis 7.0-compatibleSETsemantics because atomic publication usesSET ... NX GET.- Configure each cache backend for a specific service or purpose. For Redis, use a dedicated database, endpoint, or deployment-level key namespace in the connection/configuration instead of sharing one general cache for unrelated data.
[!WARNING]
Cache.Flushfollows backend semantics; for Redis it clears the selected database.