The File store offers two modes of operation; caching (the default) and non-caching.
With caching mode, it loads the full contents of context into memory on startup. This means a get
can be completed synchronously from memory. A set
will also return synchronously once the value is updated in memory - but an asynchronous action is kicked off to write the update to disk in the background. If using caching mode, no changes will be required to existing code that accesses context.
With non-caching mode, all get
and set
calls involve reading/writing to disk. As such the code making the request must provide a callback function. This is a change to the existing context api. For example:
flow.get("foo", function(err, foo) {
// check err in case something went wrong...
// otherwise do something with foo
});
To avoid lots of nested callbacks, the api also allows you to get multiple values in one go:
flow.get(["foo","bar","name"], function(err, foo, bar, name) {
// check err in case something went wrong...
// otherwise do something with foo, bar and name
});
The same is possible with set
-
flow.set(["foo","bar","name"],["red","blue","green"], function(err) {
// check err in case something went wrong
});
Finally, as you will be able to have multiple context stores configured, you can specify which store a particular value should be put in.
var fooFromMemoryStore = flow.get("foo","memory");
var fooFromFileStore = flow.get("foo","file");
The "memory"
and "file"
arguments are the names of context stores as configured in your settings.js
file.
I'm sure there's more to document - this is a bit of a brain dump ahead of writing the proper documentation later this week.