I just added clojure.core.cache 0.6.1 to my project, did a lein deps, followed the very short and clear example here: https://github.com/clojure/core.cache and it just flat out does not work.
Example:
$lein repl
REPL started; server listening on localhost port 20513
user=> (require '[clojure.core.cache :as cache])
nil
user=> (def fifoc (cache/fifo-cache-factory {}))
#'user/fifoc
user=> (cache/has? fifoc :foo)
false
user=> (cache/miss fifoc :foo "bar")
{:foo "bar"}
user=> (cache/has? fifoc :foo)
false
What is going wrong here? Am I completely missing the point? I've tried it with the other cache backends all with the same result. Tried it with different keys, different values, different namespace, different alias - nada. Running the tests gives me this:
$ lein test clojure.core.cache.tests
Testing clojure.core.cache.tests
Ran 13 tests containing 273 assertions.
0 failures, 0 errors.
Which makes this all the more mysterious. I looked at the tests, and while they :import the cache backends and instantiate them the java way (miss (BasicCache. {}) ...), which I also tried, that too fails for me in exactly the same way.
Any help before I just implement one that works?
cache/miss
returns a new cache object that you need to use for further operations.
Ex:
user=> (cache/has? (cache/miss fifoc :foo "bar") :foo)
true
Your example becomes:
user=> (def fifoc (atom (cache/fifo-cache-factory {})))
#'user/fifoc
user=> (swap! fifoc #(cache/miss % :foo "bar"))
{:foo "bar"}
user=> (cache/has? @fifoc :foo)
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With