Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
44
gaia/shared/js/everythingme/cache.js
Executable file
44
gaia/shared/js/everythingme/cache.js
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
/* global Promise*/
|
||||
/* global asyncStorage*/
|
||||
|
||||
(function(eme) {
|
||||
var PREFIX = 'eme-cache';
|
||||
var slice = Function.call.bind(Array.prototype.slice);
|
||||
|
||||
|
||||
function Cache() { }
|
||||
|
||||
Cache.prototype = {
|
||||
generateKey: function cache_generateKey() {
|
||||
return slice(arguments).map(JSON.stringify).join('|');
|
||||
},
|
||||
|
||||
add: function cache_add(key, value) {
|
||||
return new Promise(function ready(resolve, reject) {
|
||||
asyncStorage.setItem(PREFIX + key, value);
|
||||
});
|
||||
},
|
||||
get: function cache_get(key) {
|
||||
return new Promise(function ready(resolve, reject) {
|
||||
asyncStorage.getItem(PREFIX + key, function onValue(value) {
|
||||
if (value === null) {
|
||||
reject(null);
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
addRequest: function cache_addRequest(service, method, options, response) {
|
||||
this.add(this.generateKey(service, method, options), response);
|
||||
},
|
||||
getRequest: function cache_getRequest(service, method, options) {
|
||||
return this.get(this.generateKey(service, method, options));
|
||||
}
|
||||
};
|
||||
|
||||
eme.Cache = new Cache();
|
||||
|
||||
})(window.eme);
|
||||
Loading…
Reference in a new issue