Crates.io | wasmcloud-nats-kvcache |
lib.rs | wasmcloud-nats-kvcache |
version | 0.5.1 |
source | src |
created_at | 2021-02-11 20:39:30.749656 |
updated_at | 2021-03-18 18:32:55.909747 |
description | A key-value capability provider for wasmCloud that replicates data changes over NATS |
homepage | |
repository | https://github.com/wasmcloud/capability-providers |
max_upload_size | |
id | 353931 |
size | 56,578 |
This is an in-memory key-value cache that is distributed by replicating state changes across a specific set of NATS topics. It is understood that in the "bare NATS" version of this provider, message loss can potentially happen and thus the cache values can potentially diverge from host to host.
It is recommended that this key-value store be used in development, debugging, and R&D purposes only and you not use this for a production distributed cache unless periodic node divergence is an acceptable use case (for example, you re-query data upon cache misses or time-delayed/heartbeat reconciliation is acceptable). This provider will attempt to use high water marks + event sourcing to reconcile global state, but that system is not infallible.
As per the wasmcloud:keyvalue
contract, all values (except for atomics) stored by this provider are treated as strings. Sets
are treated as sets of strings, etc. Atomic values cannot guarantee global atomicity. Increments and decrements will be done relative to the currently known (local) value at the time, which means concurrent, distributed so-called "atomic" updates can result in inconsistent values.
Also note that caches are not isolated per actor. This is not a multi-tenant cache. If two different actors bound to the same named link instance of this provider request the same key, they will get the same value. If you need to segment distributed caches, do so by providing different link names during start-up.
This provider will take the configuration received from the first linked actor and use that data to connect to NATS. All subsequent attempts to provide link configuration will be ignored in order to satisfy the "idempotent provider" requirement. If no NATS connection string information is provided during the initial link configuration, then this provider will effectively perform like a single, standalone in-memory cache and not replicate or subscribe to any state changes.
Do not rely on this provider to return meaningful data in response to mutation operations. For example, the atomic add operation, by contract, returns an integer that should represent the new value. For optimization purposes, this provider will return the default (empty) version of all responses. This is based on the notion that when you are setting data in this distributed cache, you are not interested in immediately retrieving the value.