Open gimox opened 9 years ago
I use this script to patch it with $provide.decorator
app.config(function($provide) {
$provide.decorator('localStorageService', function($delegate) {
var original;
original = {
remove: $delegate.remove,
set: $delegate.set,
get: $delegate.get
};
$delegate.my_cache = {};
$delegate.remove = function(key) {
delete this.my_cache[key];
return original.remove.call(this, key);
};
$delegate.set = function(key, val) {
this.my_cache[key] = val;
return original.set.call(this, key, val);
};
$delegate.get = function(key) {
var val;
if (this.my_cache.hasOwnProperty(key)) {
return this.my_cache[key];
}
val = original.get.call(this, key);
this.my_cache[key] = val;
return val;
};
return $delegate;
});
});
request for memory cache.
if key is present in memory, serve it from, memory else call storage (cookie/db). when set a key save to memory and local storage.
this is the only think that this class need.