A cache of query results, as yesql query middleware.
A query is cached by giving it a cache-name info value: a vector of strings and keywords, where each keyword is replaced by the query argument of that name. A query's results are cached under that name (and the query name and arguments), and another query can clear everything cached under a name with invalidate-cache-names:
-- name: get-items-by-list
-- info-cache-name: ["list" :list_id]
SELECT * FROM item WHERE list_id = :list_id
-- name: add-item!
-- info-invalidate-cache-names: [["list" :list_id]]
INSERT INTO item (list_id, title) VALUES (:list_id, :title)
The cache itself is an atom, made by make-query-cache, that queries use only while it's bound with with-query-cache (or call-with-query-cache). With no cache bound, queries run uncached.
A cache of query results, as yesql query middleware.
A query is cached by giving it a cache-name info value: a vector of
strings and keywords, where each keyword is replaced by the query
argument of that name. A query's results are cached under that name
(and the query name and arguments), and another query can clear
everything cached under a name with invalidate-cache-names:
-- name: get-items-by-list
-- info-cache-name: ["list" :list_id]
SELECT * FROM item WHERE list_id = :list_id
-- name: add-item!
-- info-invalidate-cache-names: [["list" :list_id]]
INSERT INTO item (list_id, title) VALUES (:list_id, :title)
The cache itself is an atom, made by make-query-cache, that queries
use only while it's bound with with-query-cache (or
call-with-query-cache). With no cache bound, queries run uncached.(call-with-query-cache query-cache f)Call f with query-cache as the cache for queries it runs.
Call f with query-cache as the cache for queries it runs.
(clear-cache!)Clear everything in the current query cache, if one is bound.
Clear everything in the current query cache, if one is bound.
(current-query-cache)The query cache bound for the current thread, or nil.
The query cache bound for the current thread, or nil.
(invalidate-cache! cache-name)Clear what's cached under cache-name (a vector, like a query's cache-name with its arguments filled in) in the current query cache, if one is bound.
Clear what's cached under cache-name (a vector, like a query's cache-name with its arguments filled in) in the current query cache, if one is bound.
(make-query-cache)A new, empty query cache.
A new, empty query cache.
(query-cache-middleware query-fn)Query middleware that caches and invalidates query results in the current query cache, according to each query's cache-name and invalidate-cache-names info values.
Query middleware that caches and invalidates query results in the current query cache, according to each query's cache-name and invalidate-cache-names info values.
(with-query-cache query-cache & body)Run body with query-cache as the cache for queries it runs.
Run body with query-cache as the cache for queries it runs.
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 |