Created
September 6, 2018 11:23
-
-
Save zerobias/dbc938fb49502a47494bff5aab353586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const defaultCache = store => { | |
return { | |
invalidate: hash => | |
new Promise(resolve => { | |
delete store[hash]; | |
resolve(hash); | |
}), | |
invalidateAll: () => | |
new Promise(resolve => { | |
store = {}; | |
resolve(); | |
}), | |
read: hash => | |
new Promise(resolve => { | |
resolve(store[hash] || null); | |
}), | |
update: callback => | |
new Promise(resolve => { | |
if (typeof callback === 'function') { | |
Object.keys(store).forEach(key => { | |
callback(store, key, store[key]); | |
}); | |
} | |
resolve(); | |
}), | |
write: (hash, data) => | |
new Promise(resolve => { | |
store[hash] = data; | |
resolve(hash); | |
}), | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment