Although it is possible to use memo-clear! to force a refresh, we are caching for efficiency purposes, so it would be nice to provide an easy way to manually set cache values. This is one way to implement it:
(defn memo-miss!
"Reaches into a core.memo-populated function and sets the cached value
for a given seq of function args."
[f args result]
(when-let [cache (cache-id f)]
(swap! cache clojure.core.cache/miss args (delay result))))
(testing "that setting cache values works as expected"
(is (memo-clear! id))
(is (memo-miss! id [29] :x))
(is (= :x (id 29)))
(is (= 42 (id 42))))
Following the existing code style, this could be written as:
(defn memo-miss!
"Reaches into a core.memo-populated function and sets the cached value
for a given seq of function args."
[f args result]
(when-let [cache (cache-id f)]
(swap! cache
(constantly (clojure.core.cache/miss @cache args (delay result))))))
I don't understand why swap!... constantly is preferred, or how it is any different than reset!, but I also don't have the decades of experience of the maintainers!