core.cache

Overwriting entries in LRU-cache deletes LRU key-values unnecessarily

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

To "overwrite" the value in an LRUCache, one uses assoc. Surprisingly, another k,v entry is evicted, even though the total number of items in the cache should not be increased by overwriting.

Demo:

(def C0 (lru-cache-factory {} :threshold 3))
; --> #<Var@7ec74910: {}>

(def C1 (-> C0 (assoc :a 1) (assoc :b 2) (assoc :c 3)))
; --> #<Var@315863e4: {:c 3, :b 2, :a 1}>

(-> C1 (assoc :a 4) (assoc :a 5) (assoc :a 6))
; --> {:a 6}

Activity

Hide
Fogus added a comment -

I've pushed a commit to master that I believe fixes this problem. I'll look at it a bit more and will release a v0.6.1 version ASAP.
Thank you

Show
Fogus added a comment - I've pushed a commit to master that I believe fixes this problem. I'll look at it a bit more and will release a v0.6.1 version ASAP. Thank you
Hide
Fogus added a comment -

version 0.6.1 has been pushed out to Maven central.

Show
Fogus added a comment - version 0.6.1 has been pushed out to Maven central.
Hide
Fogus added a comment -

v0.6.1 pushed to Maven Central.

Show
Fogus added a comment - v0.6.1 pushed to Maven Central.
Hide
Si Yu added a comment -

It appears v0.6.1 still has not fixed the issue

(-> (cache/lru-cache-factory {} :threshold 2)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3))
{:b 3}

Show
Si Yu added a comment - It appears v0.6.1 still has not fixed the issue (-> (cache/lru-cache-factory {} :threshold 2) (assoc :a 1) (assoc :b 2) (assoc :b 3)) {:b 3}
Hide
Arthur Edelstein added a comment -

Works for me in 0.6.2. Thanks, Fogus!

(-> (cache/lru-cache-factory {} :threshold 2)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3))

; {:b 3, :a 1}

Show
Arthur Edelstein added a comment - Works for me in 0.6.2. Thanks, Fogus! (-> (cache/lru-cache-factory {} :threshold 2) (assoc :a 1) (assoc :b 2) (assoc :b 3)) ; {:b 3, :a 1}

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: