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
  {: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.

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

StoreStateclj

source

wait-if-staleclj

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

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

× close