Config store functionality and implementation.
Config store functionality and implementation. See: [[make-dynamic-store]], [[make-caching-store]]
(fetch-every? duration-millis)
Given duration in milliseconds, return a fetch decider (predicate) function
(fn [^keypin.type.StoreState store-state]) -> boolean
that returns true
if the duration has elapsed, false
otherwise.
See: make-dynamic-store
Given duration in milliseconds, return a fetch decider (predicate) function ``` (fn [^keypin.type.StoreState store-state]) -> boolean ``` that returns `true` if the duration has elapsed, `false` otherwise. See: [[make-dynamic-store]]
(fetch-if-error? err-ts-key millis-since-error)
Given error-timestamp key and duration since error, return a fetch decider (predicate) function
(fn [^keypin.type.StoreState store-state]) -> boolean
that returns true
if error happened + duration elapsed,
false
if error happened + duration NOT elapsed, true
otherwise.
Error occured? | Duration elapsed? | Return |
---|---|---|
Yes | Yes | True |
No | False | |
No | True |
See: make-dynamic-store
Given error-timestamp key and duration since error, return a fetch decider (predicate) function ``` (fn [^keypin.type.StoreState store-state]) -> boolean ``` that returns `true` if error happened + duration elapsed, `false` if error happened + duration NOT elapsed, `true` otherwise. |Error occured?|Duration elapsed?|Return| |--------------|-----------------|------| | Yes | Yes | True | | | No | False| | No | | True | See: [[make-dynamic-store]]
(make-caching-store store)
Wrap a given store (map, vector or keypin.type/IStore instance) such that the key-definition lookups are cached.
For dynamic stores (that implement clojure.lang.IDeref
) the cache is valid as long as the underlying store data
doesn't change.
Wrap a given store (map, vector or keypin.type/IStore instance) such that the key-definition lookups are cached. For dynamic stores (that implement `clojure.lang.IDeref`) the cache is valid as long as the underlying store data doesn't change.
(make-dynamic-store f)
(make-dynamic-store
f
{:keys [name init fetch? verify-sanity error-handler]
:or {name (gensym "dynamic-store:")
fetch? (let [f? (fetch-every? 1000) e? (fetch-if-error? :err-ts 1000)]
(fn [db] (and (f? db) (e? db))))
verify-sanity (wait-if-stale 5000 1000)
error-handler
(fn [data-holder ex]
(let [err-ts (i/now-millis)]
(binding [*out* *err*]
(printf "Error refreshing dynamic store %s at %s\n"
(i/as-str name)
(.format (SimpleDateFormat.
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
(Date. err-ts)))
(cs/print-stack-trace ex)
(flush))
(send data-holder
update
:err-ts
(fn [old-err-ts]
(max (long (or old-err-ts 0)) err-ts)))))}
:as options})
Given a fetch function (fn [old-data]) -> new-data
that fetches a map instance, create a dynamic store that
refreshes itself.
Kwarg | Type/format | Description | Default |
---|---|---|---|
:name | stringable | Name of the config store | Auto generated |
:init | map | Initial data | nil : Initialized asynchronously |
:fetch? | (fn [^StoreState ss])->bool | Return true to re-fetch now | Fetch at 1 sec interval |
:verify-sanity | (fn [StoreState-holder]) | Verify store sanity | Wait max 1 sec for 5+ sec old data |
:error-handler | (fn [StoreState-holder ex]) | respond to async fetch error | Prints the error |
You may deref StoreState-holder to access its contents.
(make-dynamic-store f) ; async initialization, refresh interval 1 second
(make-dynamic-store f {:init (f)}) ; upfront initialization, refresh interval 1 second
Given a fetch function `(fn [old-data]) -> new-data` that fetches a map instance, create a dynamic store that refreshes itself. ### Options | Kwarg | Type/format | Description | Default | |----------------|-----------------------------|-----------------------------|---------| |`:name` | stringable | Name of the config store | Auto generated | |`:init` | map | Initial data | `nil`: Initialized asynchronously | |`:fetch?` |`(fn [^StoreState ss])->bool`| Return true to re-fetch now | Fetch at 1 sec interval | |`:verify-sanity`|`(fn [StoreState-holder])` | Verify store sanity | Wait max 1 sec for 5+ sec old data | |`:error-handler`|`(fn [StoreState-holder ex])`| respond to async fetch error| Prints the error | You may deref StoreState-holder to access its contents. ### Examples ``` (make-dynamic-store f) ; async initialization, refresh interval 1 second (make-dynamic-store f {:init (f)}) ; upfront initialization, refresh interval 1 second ```
(wait-if-stale stale-millis timeout-millis)
Given staleness duration and refresh-wait timeout in milliseconds, return a function (fn [state-agent])
that
detects stale store and waits until timeout for a refresh.
See: make-dynamic-store
Given staleness duration and refresh-wait timeout in milliseconds, return a function `(fn [state-agent])` that detects stale store and waits until timeout for a refresh. See: [[make-dynamic-store]]
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close