<< Back to previous view

[CCACHE-31] SoftCaches update in-place, other cache types don't Created: 25/Jul/13  Updated: 04/Aug/14

Status: Open
Project: core.cache
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Tassilo Horn Assignee: Fogus
Resolution: Unresolved Votes: 1
Labels: None

Attachments: File immutable.diff    

 Description   

I've successfully used SoftCaches in my project, and now I had the need for another simple cache, so I've created a BasicCache. Thereby, I fell into the trap that while SoftCaches update in-place, BasicCaches don't (and looking at the code, all other cache types except for aforementioned SoftCache don't, too).

user> (def C (cache/soft-cache-factory {}))
#'user/C
user> (cache/miss C :a 1)
{:a #<SoftReference java.lang.ref.SoftReference@2bf31c53>}
user> C
{:a #<SoftReference java.lang.ref.SoftReference@2bf31c53>} ;; updated in-place
user> (def C (cache/basic-cache-factory {}))
#'user/C
user> (cache/miss C :a 1)
{:a 1}
user> C                                                    ;; nope, no update, still initial value
{}

So with every cache type except for SoftCaches, you have to use the return value of `miss` (and `evict`). But the documentation doesn't mention that at all. The typical has?/miss/hit snippets explaining the usage pattern also discard the value of `miss`.

IMHO, a cache is something mutable and should of course update in place. I mean, when you `(def C (some-cache...))`, are you really supposed to use `alter-var-root` or make the cache Var dynamic and use `set!`?



 Comments   
Comment by Ambrose Bonnaire-Sergeant [ 04/Aug/14 1:52 PM ]

Patch distinguishes between mutable and immutable caches, and classifies SoftCache and TTLCache as mutable.

Generated at Sun Dec 21 21:31:52 CST 2014 using JIRA 4.4#649-r158309.