(cached cache-container env cache-key f)
Try to read some value from a cache, otherwise run and cache it.
cache-container is a keyword for the cache container name, consider that the environment has multiple cache atoms. If the cache-container key is not present in the env, the cache will be ignored and will always run f.
cache-key is how you decide, in that cache container, what key should be used for this cache try.
f needs to a function of zero arguments.
Example:
(cached ::my-cache {::my-cache (atom {})} [3 :foo]
(fn [] (run-expensive-operation)))
Try to read some value from a cache, otherwise run and cache it. cache-container is a keyword for the cache container name, consider that the environment has multiple cache atoms. If the cache-container key is not present in the env, the cache will be ignored and will always run f. cache-key is how you decide, in that cache container, what key should be used for this cache try. f needs to a function of zero arguments. Example: (cached ::my-cache {::my-cache (atom {})} [3 :foo] (fn [] (run-expensive-operation)))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close