Skip to main content

ttlru

Stores key/value pairs in a ttlru in-memory cache. This cache is therefore reset every time the service restarts.

# Common config fields, showing default values
label: ""
ttlru:
cap: 1024
default_ttl: 5m0s
init_values: {}

The cache ttlru provides a simple, goroutine safe, cache with a fixed number of entries. Each entry has a per-cache defined TTL.

This TTL is reset on both modification and access of the value. As a result, if the cache is full, and no items have expired, when adding a new item, the item with the soonest expiration will be evicted.

It uses the package expirable

The field init_values can be used to pre-populate the memory cache with any number of key/value pairs:

cache_resources:
- label: foocache
ttlru:
default_ttl: '5m'
cap: 1024
init_values:
foo: bar

These values can be overridden during execution.

Fields

cap

The cache maximum capacity (number of entries)

Type: int
Default: 1024

default_ttl

The cache ttl of each element

Type: string
Default: "5m0s"
Requires version 4.21.0 or newer

ttl

Deprecated. Please use default_ttl field

Type: string

init_values

A table of key/value pairs that should be present in the cache on initialization. This can be used to create static lookup tables.

Type: object
Default: {}

# Examples

init_values:
Nickelback: "1995"
Spice Girls: "1994"
The Human League: "1977"

optimistic

If true, we do not lock on read/write events. The ttlru package is thread-safe, however the ADD operation is not atomic.

Type: bool
Default: false