# s3FifoCache

> **s3FifoCache**<`K`, `V`>(`options`): [`Cache`](/reference/knotkit/cache/interfaces/cache/)<`K`, `V`>

Defined in: [packages/cache/src/s3-fifo-cache.ts:226](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cache/src/s3-fifo-cache.ts#L226)

Create a [Cache](/reference/knotkit/cache/interfaces/cache/) that evicts with S3-FIFO (simple, static, scalable FIFO queues).

Choose it when the traffic mixes a reused hot set with long scans of keys read once, or with many keys never read again: a new key waits in a small probationary queue, a tenth of capacity, and only a key read twice there reaches the main queue, so a scan cannot push the hot set out. Keys evicted from the probationary queue are remembered, without their values, so one that returns soon enters the main queue directly; those keys stay reachable until forgotten, at most one per entry in the main queue.

`get` and a `set` of a key already held count as uses; `peek` and `has` do not.

`get`, `peek`, `has`, and `delete` run in O(1) average time; `set` runs in O(1) amortized time per entry it evicts, since an entry is passed over at most a bounded number of times per use. Iteration is O(n) over every slot allocated since the last `clear`.

## Type Parameters

### K

`K`

### V

`V`

## Parameters

### options

[`CacheOptions`](/reference/knotkit/cache/interfaces/cacheoptions/)<`K`, `V`>

## Returns

[`Cache`](/reference/knotkit/cache/interfaces/cache/)<`K`, `V`>

## Throws

With `INVALID_CAPACITY` when `capacity` is not a positive safe integer (or, with `weigh`, not a positive finite number), `MISSING_CLOCK` when `timeToLive` comes without `clock`, or `INVALID_TIME_TO_LIVE` when `timeToLive` is not a positive finite number.

## Example

```ts
const cache = s3FifoCache<string, number>({ capacity: 3 })
cache.set('a', 1)
cache.set('b', 2)
cache.set('c', 3)
cache.get('a')
cache.get('a')
cache.set('d', 4) // [{ key: 'b', value: 2 }]: 'a' moved to the main queue
```
