Lookup cache for Datastar component resolution.
WHAT IS CACHED: the resolved NAMESPACE SYMBOLS, never the vars.
The expensive half of discovery/discover-component is the search-path scan:
for "chat.chat" an earlier prefix such as my.app.admin.components does not hold it, so
require throws a FileNotFoundException (stack trace and all) before the scan
falls through to my.app.components.chat.chat. That answer never
changes for a given [component-name controller-name] pair, so it is what we
store. Turning the cached symbols back into vars is a namespace-map lookup
with no I/O, and it is done on every hit — which keeps the cache REPL-safe:
caching the vars themselves would survive an ordinary defn re-evaluation
(same var object, new root binding) but go stale on remove-ns / :reload-all,
which mint brand-new var objects.
Deliberately NOT cache.interface: that component's contract is
EDN-serializable values under a TTL, and it would add a cross-component
dependency to the intentionally generic datastar component.
Lookup cache for Datastar component resolution. WHAT IS CACHED: the resolved NAMESPACE SYMBOLS, never the vars. The expensive half of `discovery/discover-component` is the search-path scan: for "chat.chat" an earlier prefix such as `my.app.admin.components` does not hold it, so `require` throws a FileNotFoundException (stack trace and all) before the scan falls through to `my.app.components.chat.chat`. That answer never changes for a given [component-name controller-name] pair, so it is what we store. Turning the cached symbols back into vars is a namespace-map lookup with no I/O, and it is done on every hit — which keeps the cache REPL-safe: caching the vars themselves would survive an ordinary `defn` re-evaluation (same var object, new root binding) but go stale on `remove-ns` / `:reload-all`, which mint brand-new var objects. Deliberately NOT `cache.interface`: that component's contract is EDN-serializable values under a TTL, and it would add a cross-component dependency to the intentionally generic `datastar` component.
(cached k)The cached resolution for k, or nil when absent. nil is a NORMAL outcome.
The cached resolution for `k`, or nil when absent. nil is a NORMAL outcome.
(cached-count)How many resolutions are cached.
How many resolutions are cached.
(cached-keys)The set of cached [component-name controller-name] keys.
The set of cached [component-name controller-name] keys.
(clear!)Removes every entry. Returns nil.
Removes every entry. Returns nil.
(evict! k)Removes the entry under k. Idempotent. Returns nil.
Removes the entry under `k`. Idempotent. Returns nil.
(get-or-resolve! k resolve-fn)(get-or-resolve! k resolve-fn cacheable?)Cache-aside. Returns the cached resolution for k, else calls resolve-fn
(0-arity) and returns its result, storing it when cacheable? says so
(default: any non-nil result).
Hits take no lock; misses are serialized and re-check the cache inside the lock, so concurrent callers resolve a given component exactly once.
FAILURES ARE NEVER CACHED: a nil result is not stored, an incomplete one is
returned but not stored, and an exception from resolve-fn propagates with
nothing written — the next call retries.
Cache-aside. Returns the cached resolution for `k`, else calls `resolve-fn` (0-arity) and returns its result, storing it when `cacheable?` says so (default: any non-nil result). Hits take no lock; misses are serialized and re-check the cache inside the lock, so concurrent callers resolve a given component exactly once. FAILURES ARE NEVER CACHED: a nil result is not stored, an incomplete one is returned but not stored, and an exception from `resolve-fn` propagates with nothing written — the next call retries.
(store! k v)Stores v under k, overwriting. Returns v.
Stores `v` under `k`, overwriting. Returns `v`.
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 |