jellyfin-web/dashboard-ui/bower_components/emby-apiclient/appstorage-cache.js

48 lines
968 B
JavaScript
Raw Normal View History

2016-08-16 11:54:08 -07:00
define([], function () {
2016-10-01 23:13:04 -07:00
'use strict';
2016-08-16 11:54:08 -07:00
var myStore = {};
var cache;
var localData;
function updateCache() {
cache.put('data', new Response(JSON.stringify(localData)));
}
myStore.setItem = function (name, value) {
if (localData) {
2016-10-01 23:13:04 -07:00
var changed = localData[name] !== value;
2016-08-16 11:54:08 -07:00
if (changed) {
localData[name] = value;
updateCache();
}
}
};
myStore.getItem = function (name) {
if (localData) {
return localData[name];
}
};
myStore.removeItem = function (name) {
if (localData) {
localData[name] = null;
delete localData[name];
updateCache();
}
};
myStore.init = function () {
return caches.open('embydata').then(function (result) {
cache = result;
localData = {};
});
};
return myStore;
});