File: TTL.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 (25 lines) | stat: -rw-r--r-- 909 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
# TTL memoization

The time-to-live cache is one that evicts items that are older than a time-to-live threshold (in milliseconds).

## General use

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

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

Example code is as follows:

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

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

The default `:ttl/threshold` value is 2 seconds before the TTL logic is applied.

Please read the [clojure.core.cache information regarding TTL caches](https://github.com/clojure/core.cache/wiki/TTL) 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.