Hi,
I have been exploring to use core.cache and core.memoize in our clojure app and have found several issues. Those issues should have been directed to Fogus but just in case anyone has clues.
core.cache (v0.6.0):
1) it appears the cache is "broken" once two entries with a same key with different values are cache in a row
user> (-> (clojure.core.cache/lru-cache-factory {} :threshold 2)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3)
(assoc :a 4))
{:a 4}
- expects {:a 4 :b 3}
(-> (clojure.core.cache/lru-cache-factory {} :threshold 3)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3)
(assoc :c 4)
(assoc :d 5)
(assoc :e 6))
{:e 6, :d 5}
- expects {:e 6, :d 5, :c 4}
2) I wonder why the miss fn needs eviction case even if the cache has not reach the threshold limit, this appears to be the cause of the issue 1) above
(defcache LRUCache [cache lru tick limit]
...
(miss [_ item result]
(let [tick+ (inc tick)]
(if-let [ks (keys lru)]
(let [k (apply min-key lru ks)]
(LRUCache. (-> cache (dissoc k) (assoc item result)) ;; eviction case
(-> lru (dissoc k) (assoc item tick+))
tick+
limit))
(LRUCache. (assoc cache item result) ;; no change case
(assoc lru item tick+)
tick+
limit))))
core.memoize: it does not work with core.cache with version above 0.5.0
Thanks,
siyu