Provides SQLCache
, an implementation of clojure.core.cache/CacheProtocol
.
It is used with clojure.core.memoize/PluggableMemoization
This namespace exposes memo-sqlite
function which takes a
function to memoize and cache-spec, it retuns the memoized function.
This function uses the SQLCache
for memoization.
Provides `SQLCache`, an implementation of `clojure.core.cache/CacheProtocol`. It is used with `clojure.core.memoize/PluggableMemoization` This namespace exposes `memo-sqlite` function which takes a function to memoize and cache-spec, it retuns the memoized function. This function uses the `SQLCache` for memoization.
(fetch-item! k
{:keys [db-spec key-prefix deserialize-fn table key-col
value-col]})
Performs lookup by querying on the cache table. Retuens deserialized cached item.
Performs lookup by querying on the cache table. Retuens deserialized cached item.
(memo-sqlite f cache-spec)
Memoizes the given function f
using SQLCache
for caching.
SQLCache
uses a SQL backend to store return values of f
.
Example usage with SQLite:
(def memo-f
(memo-sqlite (fn [arg] (Thread/sleep 5000) arg)
{:key-prefix "artifact-repository"
:key-col "key"
:value-col "value"
:ttl 2000
:table "cache"
:serialize-fn identity
:deserialize-fn read-string
:db-spec {:dbtype "sqlite"
:classname "org.sqlite.JDBC"
:subprotocol "sqlite"
:subname "data/my-cache.db"}}))
(memo-f 1) ;; takes more than 5 seconds to return.
(memo-f 1) ;; return immediately from cache.
Memoizes the given function `f` using `SQLCache` for caching. `SQLCache` uses a SQL backend to store return values of `f`. Example usage with SQLite: ``` (def memo-f (memo-sqlite (fn [arg] (Thread/sleep 5000) arg) {:key-prefix "artifact-repository" :key-col "key" :value-col "value" :ttl 2000 :table "cache" :serialize-fn identity :deserialize-fn read-string :db-spec {:dbtype "sqlite" :classname "org.sqlite.JDBC" :subprotocol "sqlite" :subname "data/my-cache.db"}})) (memo-f 1) ;; takes more than 5 seconds to return. (memo-f 1) ;; return immediately from cache. ```
(refresh! k
v
{:keys [db-spec key-prefix table key-col value-col serialize-fn ttl]})
(stale? {:keys [ttl cached_ts]})
Tests if ttl
has expired for a cached item.
When ttl
is nil
item is not stale.
Otherwise ttl
is compared with cached_ts
.
Tests if `ttl` has expired for a cached item. When `ttl` is `nil` item is not stale. Otherwise `ttl` is compared with `cached_ts`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close