-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
37 lines (27 loc) · 1.62 KB
/
core.clj
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
28
29
30
31
32
33
34
35
36
37
(ns strojure.memoize-one.core
"Memoization of the single value.")
(set! *warn-on-reflection* true)
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defprotocol LoadingCache
"Functions for the cached computation."
(get-ref
^clojure.lang.IDeref [cache]
"Returns cached value reference to `deref`."))
(defprotocol MemoizedRef
"Cache related functions for the wrapped cached reference."
(evict
[ref]
"Invalidates this reference in the cache. Returns nil."))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defn get-value
"Returns result of `(deref (get-ref cache))`."
{:inline (fn [cache] `(.deref (get-ref ~cache)))
:added "1.1"}
[cache]
(.deref (get-ref cache)))
(defn get-another-ref
"Invalidates memoized ref and returns actual (probably new) ref from the cache."
[cache ref]
(evict ref)
(get-ref cache))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••