(cached f)Accepts a function and creates cached version of it which uses Caffeine Loading Cache.
Cache options should can be provided as meta to function. Supported options are:
:expire - expiration time (in seconds)
:refresh - refresh time (in seconds)
:when - function for checking if value should be cached
Examples: (cached ^{:expire 86400 :refresh 36000} (fn [db id] (query db id)))
;; calculate todays order capacity until it reaches zero (cached ^{:when zero?} (fn [db worker-id] (order-capacity db worker-id)))
Accepts a function and creates cached version of it which uses Caffeine Loading Cache.
Cache options should can be provided as meta to function. Supported options are:
`:expire` - expiration time (in seconds)
`:refresh` - refresh time (in seconds)
`:when` - function for checking if value should be cached
Examples:
(cached ^{:expire 86400 :refresh 36000}
(fn [db id] (query db id)))
;; calculate todays order capacity until it reaches zero
(cached ^{:when zero?}
(fn [db worker-id] (order-capacity db worker-id)))
(defcached name args cache-key & fn-body)Creates a function which uses Caffeine Loading Cache under the hood. Function declaration is similar to defn:
cached for more details)Example: (defcached customer-lifetime-value [db date {:customer/keys [id]}] ^{:expire 86400 :refresh 36000} [db date id] (query-customer-ltv db date id))
Creates a function which uses Caffeine Loading Cache under the hood.
Function declaration is similar to defn:
- name (symbol) with optional meta
- args (vector)
- caching key (vector) with optional meta containing cache options (see `cached` for more details)
- body
Example:
(defcached customer-lifetime-value [db date {:customer/keys [id]}]
^{:expire 86400 :refresh 36000}
[db date id]
(query-customer-ltv db date id))
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 |