(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 builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |