Skip to content
Snippets Groups Projects
Commit dc32be74 authored by Braden Shepherdson's avatar Braden Shepherdson
Browse files

Adding cache stats to metabase.lib.cache

parent a8e8e9e6
No related branches found
No related tags found
No related merge requests found
......@@ -17,12 +17,21 @@
(do
(when-not (.-__mbcache ^js x)
(set! (.-__mbcache ^js x) (atom {})))
(when-not js/window.__mbcache_stats
(set! js/window.__mbcache_stats (js-obj)))
(if-let [cache (.-__mbcache ^js x)]
(if-let [cached (get @cache subkey)]
cached
(do
(if-let [^js stats (aget js/window.__mbcache_stats subkey)]
(set! (.-hits stats) (inc (.-hits stats)))
(aset js/window.__mbcache_stats subkey (js-obj "hits" 1 "misses" 0)))
cached)
;; Cache miss - generate the value and cache it.
(let [value (f x)]
(swap! cache assoc subkey value)
(if-let [^js stats (aget js/window.__mbcache_stats subkey)]
(set! (.-misses stats) (inc (.-misses stats)))
(aset js/window.__mbcache_stats subkey (js-obj "hits" 0 "misses" 1)))
value))
(f x)))
(f x))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment