# lru

> 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: lru
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/lru
page-component-name: connect
page-version: master
page-component-version: master
page-component-title: Connect
page-relative-src-path: caches/lru.adoc
page-edit-url: https://github.com/redpanda-data/rp-connect-docs/edit/main/modules/components/pages/caches/lru.adoc
page-git-created-date: "2024-05-24"
page-git-modified-date: "2026-05-26"
---

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

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

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

#### Common

```yml
caches:
  lru:
    cap: 1000
    init_values: {}
```

#### Advanced

```yml
caches:
  lru:
    cap: 1000
    init_values: {}
    algorithm: standard
    two_queues_recent_ratio: 0.25
    two_queues_ghost_ratio: 0.5
    optimistic: false
```

This provides the lru package which implements a fixed-size thread safe LRU cache.

It uses the package [`lru`](https://github.com/hashicorp/golang-lru/v2)

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
    lru:
      cap: 1024
      init_values:
        foo: bar
```

These values can be overridden during execution.

## [](#fields)Fields

### [](#algorithm)`algorithm`

the lru cache implementation

**Type**: `string`

**Default**: `standard`

| Option | Summary |
| --- | --- |
| arc | is an adaptive replacement cache. It tracks recent evictions as well as recent usage in both the frequent and recent caches. Its computational overhead is comparable to two_queues, but the memory overhead is linear with the size of the cache. ARC has been patented by IBM. |
| standard | is a simple LRU cache. It is based on the LRU implementation in groupcache |
| two_queues | tracks frequently used and recently used entries separately. This avoids a burst of accesses from taking out frequently used entries, at the cost of about 2x computational overhead and some extra bookkeeping. |

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

The cache maximum capacity (number of entries)

**Type**: `int`

**Default**: `1000`

### [](#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 lru package is thread-safe, however the ADD operation is not atomic.

**Type**: `bool`

**Default**: `false`

### [](#two_queues_ghost_ratio)`two_queues_ghost_ratio`

is the default ratio of ghost entries kept to track entries recently evicted on two\_queues cache.

**Type**: `float`

**Default**: `0.5`

### [](#two_queues_recent_ratio)`two_queues_recent_ratio`

is the ratio of the two\_queues cache dedicated to recently added entries that have only been accessed once.

**Type**: `float`

**Default**: `0.25`