enhance: replace atom blocks-ast-cache by lrucache

This commit is contained in:
rcmerci
2025-04-03 22:14:27 +08:00
parent 1c24fff543
commit d05a8ac07f
5 changed files with 45 additions and 38 deletions

View File

@@ -2,6 +2,9 @@
"Utils about cache"
(:require [cljs.cache :as cache]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def *profile (volatile! {}))
(defn cache-fn
"Return a cached version of `f`.
cache-key&f-args-fn: return [<cache-key> <args-list-to-f>]"
@@ -9,5 +12,8 @@
(fn [& args]
(let [[cache-k f-args] (apply cache-key&f-args-fn args)
through-value-fn #(apply f f-args)
;; hit? (cache/has? @*cache cache-k)
;; _ (vswap! *profile update-in [[*cache (.-limit ^js @*cache)] (if hit? :hit :miss)] inc)
;; _ (prn (if hit? :hit :mis) cache-k)
cache (vreset! *cache (cache/through through-value-fn @*cache cache-k))]
(cache/lookup cache cache-k))))