Liking cljdoc? Tell your friends :D
Clojure only.

fmnoise.coldbrew


cachedclj

(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)))
sourceraw docstring

defcachedcljmacro

(defcached name args cache-key & fn-body)

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))

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))
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close