ampersand-local-cache-mixin
Only fetch when your data is old or stale. Easily configurable localStorage cache for ampersand & backbone state objects, models, and collections.
Note that this is not an alternate sync
implementation, this is to let you configure and trust a local cache but ultimately get your data from a remote source.
Works with Ampersand.js and Backbone in state objects, models, and collections.
install
npm install ampersand-local-cache-mixin
example
var cacheMixin = ;var Model = ;var ms = ; moduleexports = Model
Other details
There are two overwriteable methods that determine what gets stored and retrieved.
Here's how they look by default:
{ return this } { return data }
If you want to customize how it gets parsed/read from storage, simply overwrite those methods.
note: By default only props
will get stored, not session
or derived
properties
More docs?
This is really just a simple object with a few methods. It's quite short and readable, I'd suggest reading the source to know exactly what's going on.
But also,
credits
If you like this follow @HenrikJoreteg on twitter.
license
MIT