= ttlru
:type: cache
:status: stable



////
     THIS FILE IS AUTOGENERATED!

     To make changes, edit the corresponding source file under:

     https://github.com/redpanda-data/connect/tree/main/internal/impl/<provider>.

     And:

     https://github.com/redpanda-data/connect/tree/main/cmd/tools/docs_gen/templates/plugin.adoc.tmpl
////

// © 2024 Redpanda Data Inc.


component_type_dropdown::[]


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


[tabs]
======
Common::
+
--

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

--
Advanced::
+
--

```yml
# All config fields, showing default values
label: ""
ttlru:
  cap: 1024
  default_ttl: 5m0s
  ttl: "" # No default (optional)
  init_values: {}
  optimistic: false
```

--
======

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 https://github.com/hashicorp/golang-lru/v2/expirable[`expirable`^]

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

```yaml
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*: `{}`

```yml
# 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`


