[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Cache](https://evolu.dev/docs/api-reference/common/Cache) › createLruCache

```ts
function createLruCache<K, V>(
  capacity: number &
    Brand<"NonNaN"> &
    Brand<"Finite"> &
    Brand<"Int"> &
    Brand<"NonNegative"> &
    Brand<"Positive">,
): Cache<K, V>;
```

Defined in: [packages/common/src/Cache.ts:63](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Cache.ts#L63)

Creates an LRU (least recently used) cache with a maximum capacity.

When the cache reaches capacity, the least recently used entry is evicted.
Both `get` and `set` operations update the access order.

### Example

```ts
import {
  assertEqual,
  assertFalse,
  createLruCache,
  PositiveInt,
} from "@evolu/common";

const cache = createLruCache<string, number>(PositiveInt.orThrow(2));
cache.set("a", 1);
cache.set("b", 2);
// Reading "a" makes "b" the least recently used entry.
assertEqual(cache.get("a"), 1);
cache.set("c", 3);

assertFalse(cache.has("b"));
```