---
title: ttlru
page-cloud: true
latest-operator-version: v26.2.6
latest-console-tag: v3.14.0
latest-connect-version: 4.118.0
latest-redpanda-tag: v26.2.7
docname: connect/components/caches/ttlru
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: connect/components/caches/ttlru.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/develop/pages/connect/components/caches/ttlru.adoc
description: Stores key/value pairs in a ttlru in-memory cache. This cache is therefore reset every time the service restarts.
page-self-managed-available: "true"
page-self-managed-available-url: https://docs.redpanda.com/connect/components/caches/ttlru/
page-git-created-date: "2024-09-09"
page-git-modified-date: "2026-10-19"
page-generated-sources:
  - include: connect:components:partial$descriptions/caches/ttlru.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

# ttlru

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

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

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

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://pkg.go.dev/github.com/hashicorp/golang-lru/v2/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.

#### Common

```yml
cache:
  label: ""
  ttlru:
    cap: 1024
    default_ttl: 5m0s
    init_values: {}
```

#### Advanced

```yml
cache:
  label: ""
  ttlru:
    cap: 1024
    default_ttl: 5m0s
    ttl: "" # No default (optional)
    init_values: {}
    optimistic: false
```

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

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

**Default**: `{}`

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

### `ttl`

Deprecated. Please use `default_ttl` field

**Type**: `string`