core cache/memoize issue?

90 views
Skip to first unread message

siyu798

unread,
Jul 11, 2012, 2:57:18 PM7/11/12
to clo...@googlegroups.com
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

Michael Fogus

unread,
Jul 11, 2012, 7:24:29 PM7/11/12
to clo...@googlegroups.com
Thank you for the report. I have a fix for the LRU/LU caches on my box
and will have it out in the next day or so. The core.memoize changes
will follow soon after.

siyu798

unread,
Jul 13, 2012, 10:56:03 AM7/13/12
to clo...@googlegroups.com
Awesome, thx a lot!!
Reply all
Reply to author
Forward
0 new messages