# ttlru

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [connect-full.txt](https://docs.redpanda.com/connect-full.txt)

---
title: ttlru
latest-connect-version: 4.93.0
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-redpanda-tag: v26.1.9
docname: caches/ttlru
page-component-name: connect
page-version: master
page-component-version: master
page-component-title: Connect
page-relative-src-path: caches/ttlru.adoc
page-edit-url: https://github.com/redpanda-data/rp-connect-docs/edit/main/modules/components/pages/caches/ttlru.adoc
page-git-created-date: "2024-05-24"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/connect/components/caches/ttlru.md -->

**Available in:** [Cloud](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/caches/ttlru/%20%22View%20the%20Cloud%20version%20of%20this%20component%22), Self-Managed

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

#### Common

```yml
caches:
  ttlru:
    cap: 1024
    default_ttl: 5m0s
    init_values: {}
```

#### Advanced

```yml
caches:
  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 [`expirable`](https://github.com/hashicorp/golang-lru/tree/main/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)Fields

### [](#cap)`cap`

The cache maximum capacity (number of entries)

**Type**: `int`

**Default**: `1024`

### [](#default_ttl)`default_ttl`

The cache ttl of each element

Requires version 4.21.0 or later.

**Type**: `string`

**Default**: `5m0s`

### [](#init_values)`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**: `string`

**Default**: `{}`

```yaml
# Examples:
init_values:
  Nickelback: "1995"
  Spice Girls: "1994"
  The Human League: "1977"
```

### [](#optimistic)`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`

### [](#ttl)`ttl`

Deprecated. Please use `default_ttl` field

**Type**: `string`