It's definitely one of the less intuitive aspects of dealing with core.cache but it bites you once (or twice!) and you internalize it and kinda move on :)
Sean On Mar 3, 2014, at 1:57 PM, dan.stone16...@gmail.com wrote: > 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, dan.sto...@gmail.com 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)))
signature.asc
Description: Message signed with OpenPGP using GPGMail