There are other caching solutions available that do similar things, however, they all use WebStorage only, this solution uses the heap, so you're not limited to only 5MB of storage. When you need large amounts of data to be readily available to the user on a Single Page Application, this is your best bet.
There are 5 functions currently available to you in this package.
Get an entry from the cache.
var cachedData = $(document).localCache('get', item);
This creates an entry in the cache.
function functionOnCompletion(data) {
console.log(data);
}
var options = {
data: ['data', 'to', 'store'],
callback: functionOnCompletion
};
$(document).localCache('set', item, options);
Remove an entry from the cache.
$(document).localCache('remove', item)
Returns a boolean value -- if the item exists returns true
, else returns false
var itemDoesExist = $(document).localCache('exists', item);
Returns a JSON object of all items in cache
var allItemsInCache = $(document).localCache('getAll');