[new] [#175] Mark cache feature as stable
This commit is contained in:
parent
9022aad018
commit
b217db5579
1 changed files with 7 additions and 9 deletions
|
|
@ -960,16 +960,16 @@
|
||||||
This is a low-level util: in most cases you'll want `freeze` instead."
|
This is a low-level util: in most cases you'll want `freeze` instead."
|
||||||
[^DataOutput data-output x] (-freeze-with-meta! x data-output))
|
[^DataOutput data-output x] (-freeze-with-meta! x data-output))
|
||||||
|
|
||||||
;;;; Caching ; Experimental
|
;;;; Caching
|
||||||
|
|
||||||
|
(def ^ThreadLocal -cache-proxy
|
||||||
|
"{[<x> <meta>] <idx>} for freezing, {<idx> <x-with-meta>} for thawing."
|
||||||
;; Nb: don't use an auto initialValue; can cause thread-local state to
|
;; Nb: don't use an auto initialValue; can cause thread-local state to
|
||||||
;; accidentally hang around with the use of `freeze-to-out!`, etc.
|
;; accidentally hang around with the use of `freeze-to-out!`, etc.
|
||||||
;; Safer to require explicit activation through `with-cache`.
|
;; Safer to require explicit activation through `with-cache`.
|
||||||
(def ^ThreadLocal -cache-proxy
|
|
||||||
"{[<x> <meta>] <idx>} for freezing, {<idx> <x-with-meta>} for thawing."
|
|
||||||
(proxy [ThreadLocal] []))
|
(proxy [ThreadLocal] []))
|
||||||
|
|
||||||
(defmacro ^:private with-cache
|
(defmacro with-cache
|
||||||
"Executes body with support for freezing/thawing cached values.
|
"Executes body with support for freezing/thawing cached values.
|
||||||
|
|
||||||
This is a low-level util: you won't need to use this yourself unless
|
This is a low-level util: you won't need to use this yourself unless
|
||||||
|
|
@ -984,9 +984,7 @@
|
||||||
|
|
||||||
(deftype Cached [val])
|
(deftype Cached [val])
|
||||||
(defn cache
|
(defn cache
|
||||||
"Experimental, subject to change. Feedback welcome!
|
"Wraps value so that future writes of the same wrapped value with same
|
||||||
|
|
||||||
Wraps value so that future writes of the same wrapped value with same
|
|
||||||
metadata will be efficiently encoded as references to this one.
|
metadata will be efficiently encoded as references to this one.
|
||||||
|
|
||||||
(freeze [(cache \"foo\") (cache \"foo\") (cache \"foo\")])
|
(freeze [(cache \"foo\") (cache \"foo\") (cache \"foo\")])
|
||||||
|
|
@ -1051,7 +1049,7 @@
|
||||||
(vswap! cache_ assoc idx x)
|
(vswap! cache_ assoc idx x)
|
||||||
x)
|
x)
|
||||||
v))
|
v))
|
||||||
(throw (ex-info "No cache_ established, can't thaw. See `with-cache`." {}))))))
|
(throw (ex-info "Can't thaw without cache available. See `with-cache`." {}))))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(thaw (freeze [(cache "foo") (cache "foo") (cache "foo")]))
|
(thaw (freeze [(cache "foo") (cache "foo") (cache "foo")]))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue