In case anyone was wondering I worked out what was going on and it makes perfect sense. I was being stupid :)
If you ask for a value via 'lookup' expired values will not be returned at this point as 'has?' is called internally. I made a quick and dirty library to reflect the behaviour I want for my particular use case: https://github.com/danstone/clj-refresh-cache On Friday, February 28, 2014 9:47:14 PM UTC, [email protected] wrote: > > Taking the code below, if I repeatedly read from a cache I will > occasionally get nil back from the cache. This seems to happen on my > machine for ttl's under 5 ms. > Although I'm sure I would never use such a short TTL in the wild, I would > like to know why I am seeing this... Has anybody else noticed this issue? > > (ns cache-test.core > (:require [clojure.core.cache :as cache])) > > (def data (atom "foo")) > > (def ttl > (atom (cache/ttl-cache-factory {} :ttl 1))) > > (defn get-data > [] > (let [c @ttl > nc (if (cache/has? c {}) > (cache/hit c {}) > (cache/miss c {} @data))] > (reset! ttl nc) > (cache/lookup nc {}))) > > (def results (atom '())) > > ;; there will *sometimes* be > ;; nil elements in the seq, seems dependent on cpu speed, which would make > sense due to side effect of taking system/currentTimeMillis internally. > (set (map (fn [_] (get-data)) (range 10000))) > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
