Table of Contents
store.set, values marshalled into JSON and stored in process heap, so all threads can access it, and unmarshalled while users retrieve them via
Though very convenient, it's not recommended to use store to pass values within a transaction or request, since its overhead is more than passing objects by arguments (there are extra locking, etc.). Besides, developers have the obligation to delete the key after usage, while it's automatically managed by reference counting in passing arguments.
Following APIs are exposed to create, get and operate upon stores.
Store. Error will be thrown if the id already exists.
var store = napa.store.create('store1');
It gets a reference of store by a string identifier.
undefined will be returned if the id doesn't exist.
var store = napa.store.get('store1');
It gets a reference of store by a string identifier, or creates it if the id doesn't exist. This API is handy when you want to create a store in code that is executed by every worker of a zone, since it doesn't break symmetry.
var store = napa.store.getOrCreate('store1');
It returns count of living stores.
It gets the string identifier for the store.
It puts a transportable value into store with a string key. If key already exists, new value will override existing value.
It gets a transportable value from the store by a string key. If key doesn't exist,
undefined will be returned.
var value = store.get('status'); assert(value === 1);
It tells if a key exists in current store.
It tells how many keys are stored in current store.