General-purpose API call memoization backed by Datahike.
Unlike service.cache (which provides time-series gap-filling for date-range
queries), this namespace provides simple key→value memoization: if the exact
same API call (same function + same params) has been made before, return the
cached result.
Storage strategy:
:memoized/result-edn
(:db.type/string), not as component entities. This avoids the ClassCastException
that occurs on warm persistent stores when Datahike's temporal index tries to
compare non-Comparable component-entity maps (AAO-49).memo-store! retracts existing entries with the same
cache-key before transacting new data (unlike time-series which accumulates).General-purpose API call memoization backed by Datahike. Unlike `service.cache` (which provides time-series gap-filling for date-range queries), this namespace provides simple key→value memoization: if the exact same API call (same function + same params) has been made before, return the cached result. Storage strategy: - Results are serialized to a single EDN string stored under `:memoized/result-edn` (`:db.type/string`), not as component entities. This avoids the ClassCastException that occurs on warm persistent stores when Datahike's temporal index tries to compare non-Comparable component-entity maps (AAO-49). - Replacement semantics: `memo-store!` retracts existing entries with the same cache-key before transacting new data (unlike time-series which accumulates).
(cache-stats)Returns a summary of cached entries: count, oldest, newest.
Returns a summary of cached entries: count, oldest, newest.
(call-memoized-api descriptor api-fn)(call-memoized-api descriptor
api-fn
{:keys [refresh? max-age-seconds] :or {refresh? false}})Cached API call with replacement semantics for non-time-series (snapshot) data.
descriptor is a map:
:provider — cloud provider keyword (e.g. :oci)
:kind — data kind keyword (e.g. :compute, :identity, :filestorage)
:api-name — string for cache-key prefix (e.g. "compute/list-instances")
:cache-params — map of params for cache-key (e.g. {:compartment-id id})
:param-name-keywords — vector of keyword param names for legacy lookup-key
:items-key — key to extract from API result :data (default :items)
api-fn is a zero-arg function returning {:data {:items [...]}} or {:error ...}.
opts is an optional map:
:refresh? — force re-fetch (default false)
:max-age-seconds — serve cache only if younger than this (default nil = no limit)
Returns {:data {:items [...]}} or {:error ...}.
Cached API call with replacement semantics for non-time-series (snapshot) data.
`descriptor` is a map:
:provider — cloud provider keyword (e.g. :oci)
:kind — data kind keyword (e.g. :compute, :identity, :filestorage)
:api-name — string for cache-key prefix (e.g. "compute/list-instances")
:cache-params — map of params for cache-key (e.g. {:compartment-id id})
:param-name-keywords — vector of keyword param names for legacy lookup-key
:items-key — key to extract from API result :data (default :items)
`api-fn` is a zero-arg function returning {:data {:items [...]}} or {:error ...}.
`opts` is an optional map:
:refresh? — force re-fetch (default false)
:max-age-seconds — serve cache only if younger than this (default nil = no limit)
Returns {:data {:items [...]}} or {:error ...}.(invalidate! cache-key)Retracts all cached entries matching cache-key.
Retracts all cached entries matching `cache-key`.
(invalidate-by-prefix! prefix)Retracts all cached entries whose cache-key starts with prefix.
Useful for clearing all entries for a specific API, e.g. "compute/list-instances:".
Returns the number of entries retracted.
Retracts all cached entries whose cache-key starts with `prefix`. Useful for clearing all entries for a specific API, e.g. "compute/list-instances:". Returns the number of entries retracted.
(memo-call provider kind cache-key param-name-keywords api-fn)(memo-call provider
kind
cache-key
param-name-keywords
api-fn
{:keys [max-age-seconds]})Memoized API call. Returns cached results if available, otherwise calls
api-fn, caches the results, and returns them.
api-fn is a zero-arg function that returns the API results.
Options: :max-age-seconds — if the cached entry is older than this, re-fetch.
Memoized API call. Returns cached results if available, otherwise calls `api-fn`, caches the results, and returns them. `api-fn` is a zero-arg function that returns the API results. Options: :max-age-seconds — if the cached entry is older than this, re-fetch.
(memo-lookup provider kind cache-key)(memo-lookup provider kind cache-key max-age-seconds)Returns cached results for cache-key under the given provider and kind,
or nil if not cached.
When max-age-seconds is provided, returns nil if the cached entry is
stale (older than max-age-seconds).
Returns cached results for `cache-key` under the given `provider` and `kind`, or nil if not cached. When `max-age-seconds` is provided, returns nil if the cached entry is stale (older than max-age-seconds).
(memo-store! _provider _kind cache-key param-name-keywords results)Stores results under cache-key. If an entry already exists for this
key, retracts the old entry first (replacement semantics, not accumulation).
Stores `results` under `cache-key`. If an entry already exists for this key, retracts the old entry first (replacement semantics, not accumulation).
(migrate-drop-old-cache!)Retracts all memoized entities that lack a :memoized/cache-key attribute. Run once after deploying the new caching code.
Retracts all memoized entities that lack a :memoized/cache-key attribute. Run once after deploying the new caching code.
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 |