memoize
does not take into account the binding, this can be confirmed by looking at the source, where the map in the atom is entered only by arguments. Indeed, a function with dynamic reordering is not “referentially transparent” (that is, it cannot be replaced by its value).
Is there something that is stopping you from passing *config-val*
as an argument to at least the function you want to keep in memory?
user=> (source memoize) (defn memoize "Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use." {:added "1.0"} [f] (let [mem (atom {})] (fn [& args] (if-let [e (find @mem args)] (val e) (let [ret (apply f args)] (swap! mem assoc args ret) ret)))))
source share