ttl functions sometimes return nil

Description

If I (memoize/ttl) a function, near the threshold time the result from calling the memoized function will sometimes be nil.

I've attached a patch that exploits the problem in the unit tests.

Reproducing in the REPL is easy. Just call memoize/ttl fn a bunch of times and watch for nil results.

user=> (require '[clojure.core.memoize :as m])
nil

user=> (def f (m/ttl (constantly 1)))
#'user/f

user=> (dotimes [n 1000000] (when (nil? (f)) (println "nil f")))
nil f
nil f
nil f
nil f
nil f
nil

The problem seems to be that when clojure.core.cache/through gets called, the item hasn't expired, but when clojure.core.cache/lookup happens in build-memoizer, the expiration has passed.

Environment

None

Assignee

Sean Corfield

Reporter

Ryan Fowler

Labels

None

Approval

None

Patch

Code and Test

Priority

Major
Configure