Liking cljdoc? Tell your friends :D

keypin.store

Config store functionality and implementation.

See: make-dynamic-store, make-caching-store

Config store functionality and implementation.

See: [[make-dynamic-store]], [[make-caching-store]]
raw docstring

CacheStateclj

source

fetch-every?clj

(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]]
sourceraw docstring

fetch-if-error?clj

(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
YesYesTrue
NoFalse
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]]
sourceraw docstring

make-caching-storeclj

(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.
sourceraw docstring

make-dynamic-storeclj

(make-dynamic-store f)
(make-dynamic-store f options)

Given a fetch function (fn [old-data]) -> new-data that fetches a map instance, create a dynamic store that refreshes itself.

Options

KwargType/formatDescriptionDefault
:namestringableName of the config storeAuto generated
:initmapInitial datanil: Initialized asynchronously
:fetch?(fn [^StoreState ss])->boolReturn true to re-fetch nowFetch at 1 sec interval
:verify-sanity(fn [StoreState-holder])Verify store sanityWait max 1 sec for 5+ sec old data
:error-handler(fn [StoreState-holder ex])respond to async fetch errorPrints 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

See: make-dynamic-store-options

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
```

See: [[make-dynamic-store-options]]
sourceraw docstring

make-dynamic-store-optionsclj

(make-dynamic-store-options)
(make-dynamic-store-options {:keys [name fetch-interval-millis
                                    err-tstamp-millis-key fetch-backoff-millis
                                    stale-duration-millis stale-timeout-millis]
                             :or {name (gensym "dynamic-store:")
                                  fetch-interval-millis 1000
                                  err-tstamp-millis-key :err-ts
                                  fetch-backoff-millis 1000
                                  stale-duration-millis 5000
                                  stale-timeout-millis 1000}
                             :as options})

Given following options, use pre-configured utility functions to build options for make-dynamic-store.

KwargDescriptionDefault
:fetch-interval-millisMilliseconds to wait since last fetch to fetch again1000
:err-tstamp-millis-keyKey for error timestamp (millis) in StoreState:err-ts
:fetch-backoff-millisMilliseconds to wait to fetch since last error1000
:stale-duration-millisStore-data older than this duration(millis) is stale5000
:stale-timeout-millisWait max this duration(millis) to refresh stale data1000
:stale-timeout-handler(fn [^StoreState store-state]) to call on timeoutSTDERR output

See: fetch-every?, fetch-if-error?, wait-if-stale

Given following options, use pre-configured utility functions to build options for [[make-dynamic-store]].

| Kwarg                  | Description                                        | Default     |
|------------------------|----------------------------------------------------|-------------|
|`:fetch-interval-millis`|Milliseconds to wait since last fetch to fetch again|`1000`       |
|`:err-tstamp-millis-key`|Key for error timestamp (millis) in `StoreState`    |`:err-ts`    |
|`:fetch-backoff-millis` |Milliseconds to wait to fetch since last error      |`1000`       |
|`:stale-duration-millis`|Store-data older than this duration(millis) is stale|`5000`       |
|`:stale-timeout-millis` |Wait max this duration(millis) to refresh stale data|`1000`       |
|`:stale-timeout-handler`|`(fn [^StoreState store-state])` to call on timeout |STDERR output|

See: [[fetch-every?]], [[fetch-if-error?]], [[wait-if-stale]]
sourceraw docstring

StoreStateclj

source

wait-if-staleclj

(wait-if-stale stale-millis timeout-millis)
(wait-if-stale
  stale-millis
  timeout-millis
  {:keys [stale-timeout-handler]
   :or {stale-timeout-handler
          (fn
            [store-state]
            (binding
              [*out* *err*]
              (println
                (format
                  "Timed out waiting for stale dynamic store %s to be refreshed"
                  (.-store-name store-state)))
              (flush)))}
   :as options})

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 - prints to *err* by default on timeout.

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 - prints to `*err*` by default on timeout.

See: [[make-dynamic-store]]
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close