diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index c21f83c..e3c32a9 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -834,87 +834,6 @@ (mapv meta (thaw (freeze [(cache v1) (cache v2) (cache v1) (cache v2)]))))) -;;;; Semi-automatic caching ; Experimental - -(deftype CachedKeys [val recursive?]) -(defn cache-keys - "Experimental! Wraps map so that keyword, symbol and string keys will - automatically use `cache` during serialization." - ([x ] (cache-keys x false)) - ([x recursive?] - (if (instance? CachedKeys x) - (let [^CachedKeys x x - r? (.-recursive? x)] - (if (= recursive? r?) - x - (CachedKeys. (.-val x) recursive?))) - - (when (enc/some? x) - (CachedKeys. (enc/have map? x) recursive?))))) - -(defmacro ^:private auto-cache-val [v] `(if (map? ~v) (cache-keys ~v) ~v)) -(defmacro ^:private auto-cache-key [k] - `(cond* - (keyword? ~k) (if (instance? Cached ~k) ~k (Cached. ~k)) - (string? ~k) (if (instance? Cached ~k) ~k (Cached. ~k)) - (symbol? ~k) (if (instance? Cached ~k) ~k (Cached. ~k)) - :else ~k)) - -(defn- write-cached-kvs - ([^DataOutput out id-lg ^CachedKeys x] - (let [coll (.-val x) - recursive? (.-recursive? x) - cnt (count coll)] - - (write-id out id-lg) - (write-lg-count out cnt) - (if recursive? - (-run-kv! - (fn [k v] - (-freeze-with-meta! (auto-cache-key k) out) - (-freeze-with-meta! (auto-cache-val v) out)) - coll) - - (-run-kv! - (fn [k v] - (-freeze-with-meta! (auto-cache-key k) out) - (-freeze-with-meta! v out)) - coll)))) - - ([^DataOutput out id-empty id-sm id-md id-lg ^CachedKeys x] - (let [coll (.-val x) - recursive? (.-recursive? x) - cnt (count coll)] - - (if (zero? cnt) - (write-id out id-empty) - (do - (cond* - (sm-count? cnt) - (do (write-id out id-sm) - (write-sm-count out cnt)) - - (md-count? cnt) - (do (write-id out id-md) - (write-md-count out cnt)) - - :else - (do (write-id out id-lg) - (write-lg-count out cnt))) - - (if recursive? - (-run-kv! - (fn [k v] - (-freeze-with-meta! (auto-cache-key k) out) - (-freeze-with-meta! (auto-cache-val v) out)) - coll) - - (-run-kv! - (fn [k v] - (-freeze-with-meta! (auto-cache-key k) out) - (-freeze-with-meta! v out)) - coll))))))) - ;;;; (id-freezer nil id-nil)