Liking cljdoc? Tell your friends :D
Clojure only.

omega-red.cache


get-or-fetchclj

(get-or-fetch conn {:keys [fetch cache-set cache-get]})

Tiny helper for the usual 'fetch from cache, and if there's a miss, use fetch function to get the data but also cache it' Note that, only truthy values are considered cache hits! Args:

  • conn - connection to the cache - instance of Redis
  • options
    • cache-get - function to fetch from Redis, accepts the connection as its first arg
    • fetch - the function to fetch data from a slow resource
    • cache-set - the function to store data in cache, args are:
      • conn - connection to the cache
      • data - fetched data Note: You need to ensure that resuls of fetch and cache-get return the same types, e.g. Redis' SET foo 1 will cast 1 as string on read!
Tiny helper for the usual 'fetch from cache, and if there's a miss, use fetch function to get the data but also cache it'
Note that, only truthy values are considered cache hits!
Args:
- `conn` - connection to the cache - instance of `Redis`
- `options`
  - `cache-get` - function to fetch from Redis, accepts the connection as its first arg
  - `fetch` - the function to fetch data from a slow resource
  - `cache-set` - the function to store data in cache, args are:
    - `conn` - connection to the cache
    - `data` - fetched data
Note:
You need to ensure that resuls of `fetch` and `cache-get` return the same types, e.g. Redis' `SET foo 1`
will cast 1 as string on read!
sourceraw docstring

memoizeclj

(memoize conn {:keys [key fetch-fn expiry-s]})

Similar to clojure.core/memoize but for Redis. The signature differs since we need a key for lookup. Assumes that cached value can be SET and GET-ed. NOTE: This is a simple memoization strategy and does not handle expiry! Assumes that something else will handle cache update or expiry. To enable expiry, pass expiry-s in the options map Args:

  • conn - connection to Redis Opt-map:
  • fetch-fn - the function to fetch
  • key - the key to use for lookup
  • expiry-s - expiry in seconds, optional
Similar to `clojure.core/memoize` but for Redis. The signature differs since we need a `key` for lookup.
Assumes that cached value can be `SET` and `GET`-ed.
NOTE: This is a simple memoization strategy and does not handle expiry! Assumes that something else will handle
cache update or expiry. To enable expiry, pass `expiry-s` in the options map
Args:
- `conn` - connection to Redis
Opt-map:
- `fetch-fn` - the function to fetch
- `key` - the key to use for lookup
- `expiry-s` - expiry in seconds, optional
sourceraw docstring

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

× close