CacheConfig

Configuration for a CachePolicy.

This class is used to configure the behavior of a cache policy, such as setting a unique key for a cache entry, its time-to-live (TTL), and periodic cleanup parameters.

Cache key: Use key for a fixed key, or keyProvider for a key derived at execution time (e.g. from request context, user id, or arguments captured in the lambda). If keyProvider is set, it is invoked on each CachePolicy.execute and its result is used as the cache key; otherwise key is used. This allows reusing the same cache policy for multiple logical resources (e.g. keyProvider = { "user:${userId}" }).

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The maximum number of expired entries to remove in a single cleanup run. This helps to avoid long-running cleanup tasks. Defaults to 100.

Link copied to clipboard

The interval at which expired cache entries are automatically removed. If null, automatic cleanup is disabled. Defaults to null. This requires a ResilientScope to be provided to the cache policy.

Link copied to clipboard
var key: String

The unique identifier for a cache entry when keyProvider is null. Defaults to "default".

Link copied to clipboard
var keyProvider: suspend () -> String?

Optional suspend lambda that returns the cache key at execution time. If set, takes precedence over key. Use for dynamic keys (e.g. per-request, per-tenant).

Link copied to clipboard

The duration for which a cache entry is valid (time-to-live). After this period, the entry is considered expired. Defaults to 60 seconds.