Open kanwei opened 2 months ago
You are using the wrong property. The config map should be {mc/type mc/caffeine}
not {mc/cache mc/caffeine}
. mc/cache
is the keyword for function meta if you're placing the configuration into the function meta. So:
(def memo-rand-int (memo/memo (fn [] (rand-int 1000)) {mc/type mc/caffeine}) )
or
(defn memo-rand-int {mc/cache {mc/type mc/caffeine}} [] (rand-int 1000)))
(memo/memo #'memo-rand-int)
I'll add a check to throw an error if mc/cache
is passed in cache configuration as that's clearly a misuse.
You'll have to fix the docs too since the README docs are literally wrong too:
Caching an anonymous function
You can add cache to a function object (in clojure.core/memoize fashion):
(m/memo (fn [] ...) {mc/cache mc/caffeine})
My bad
Fixed Docs
Thanks for the library!
We're trying to replace core.memoize with this library, but some of the behavior is unexpected:
Doesn't seem to actually return a memoized function like core.memoize would.
Have to explicitly call defmemo:
Was wondering what the use case for memo/memo is. Thanks!