File: FIFO.md

package info (click to toggle)
core-memoize-clojure 1.0.257-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: xml: 53; sh: 28; makefile: 20
file content (27 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# FIFO memoization

A First-In-First-Out memoization cache is one that uses queuing logic for its backing store, expunging the elements at the front of the queue when a predetermined threshold is exceeded.

> In simple terms, the FIFO memoization cache will remove the element that has been in the cache the longest.

## General use

To create a core.memoize FIFO-backed memoized function use the `clojure.core.memoize/fifo` function with an optional seed map or a `:fifo/threshold` parameter:

    (memo/fifo function <seed> <:fifo/threshold number>)

Example code is as follows:

```clojure
(ns your.lib
  (:require [clojure.core.memoize :as memo]))

(def memoized-fun
  (memo/fifo identity {} :fifo/threshold 3))
```

The default `:fifo/threshold` value is 32 and refers to the number of elements in the cache required before the FIFO logic is applied.

Please read the [clojure.core.cache information regarding FIFO caches](https://github.com/clojure/core.cache/wiki/FIFO) for more detailed information, use cases and usage patterns.

As always, you should measure your system's characteristics to determine the best eviction strategy for your purposes.