This differs slighty from storing data in mongo as the data is stored in memory and expired on a LRU basis. This means access time is significantly faster for these in memory objects
Cached objects are backed by mongo for up to 30 days, so if an item is expired in memory, when you try to access it again it will be reloaded.
There is a limited amount of memory available on servers, so this should be used for few, shared configuration type objects
Using this for player data or having a large amount of objects could slow down you application as the store / reload process is more expensive than a mongo find for JSON data
Code using SparkCache should be written with the expectation that the cache may return null (if data is expired) so should be able to reconstruct and re-cache the data in this scenario.
var theCache = Spark.getCache();
signature put(string key, JSON object)
Adds an object to the cache
signature get(string key)
Gets an objects from the cache
A JavaScipt object, or null depending on whether put has ben called for the given key
var myObject = theCache.get("key");
signature remove(string key)
Remove an object from the cache
The object will be removed form the cache, and form the database. Subsequent calls to get will return null
Clears everything from the cache
signature removeAll(string pattern)
Clears all objects from the cache where the keys match the regex pattern provided.
the match pattern is ultimately used by mongo to do a $regex query, which uses
"Perl Compatible Regular Expressions" (PCRE) as the matching engine.