You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/LRU.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
LRU cache
2
2
==========
3
3
4
-
The least-recently-used cache is one that evicts items that are accessed least frequently once its threshold has been exceeded.
4
+
The least-recently-used cache is one that evicts items that are accessed least recently once its threshold has been exceeded.
5
5
6
6
> In simple terms, the LRU cache will remove the element in the cache that has not been accessed in the longest time.
7
7
@@ -13,11 +13,11 @@ General usage
13
13
To create a core.cache `LRUCache` instance you should *always* use its associated constructor function `lru-cache-factory` with an optional `:threshold` parameter:
14
14
15
15
```clojure
16
-
(nsyour.lib
16
+
(nsyour.lib
17
17
(:require [clojure.core.cache :as cache]))
18
-
18
+
19
19
(defC (cache/lru-cache-factory {} :threshold2))
20
-
20
+
21
21
(-> C (assoc:a1) (assoc:b2))
22
22
;=> {:a 1, :b 2}
23
23
```
@@ -34,11 +34,11 @@ At this point the cache has not yet crossed the set threshold of `2`, but if you
34
34
At this point the operation of the LRU cache looks exactly the same at the FIFO cache. However, the difference becomes apparent when a given cache item is "touched":
35
35
36
36
```clojure
37
-
(-> C (assoc:a1)
38
-
(assoc:b2)
37
+
(-> C (assoc:a1)
38
+
(assoc:b2)
39
39
(.hit:a) ;; ensure :a is used most recently
40
40
(assoc:c3))
41
-
41
+
42
42
;=> {:a 1, :c 3}
43
43
```
44
44
@@ -67,5 +67,5 @@ There are a few reasons why you might want to use a LRU cache:
67
67
* Tends to perform poorly when elements files are accessed occasionally but consistently while other elements are accessed very frequently for a short duration and never accessed again
68
68
* It requires more historical data to operate
69
69
* It requires a larger cache to increase efficiency
70
-
70
+
71
71
As always, you should measure your system's characteristics to determine the best eviction strategy for your purposes.
0 commit comments