Skip to content

Commit

Permalink
fix: localStorage gets used (microsoft#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Dec 3, 2020
1 parent 058dac1 commit a742b97
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export class GithubFetcher {
this._cache = {};
this._criticalSection = new CriticalSection();
if (useLocalStorage) {
this._cache.set = async (key, value) => localStorage.setItem('github-fetcher-' + key, JSON.stringify(data));
this._cache.get = async (key) => JSON.parse(localStorage.getItem('github-fetcher-' + key));
this._cache.delete = async (key) => localStorage.removeItem('github-fetcher-' + key);
this._cache.keys = async () => Object.keys(localStorage).filter(key => key.startsWith('github-fetcher-'));
this._cache.clear = async () => Object.keys(localStorage).filter(key => key.startsWith('github-fetcher-')).forEach(key => localStorage.removeItem(key));
const LOCALSTORAGE_KEY_PREFIX = 'github-fetcher-';
this._cache.set = async (key, value) => localStorage.setItem(LOCALSTORAGE_KEY_PREFIX + key, JSON.stringify(value));
this._cache.get = async (key) => JSON.parse(localStorage.getItem( + key));
this._cache.delete = async (key) => localStorage.removeItem(LOCALSTORAGE_KEY_PREFIX + key);
this._cache.keys = async () => Object.keys(localStorage).filter(key => key.startsWith(LOCALSTORAGE_KEY_PREFIX)).map(key => key.substr(LOCALSTORAGE_KEY_PREFIX.length));
this._cache.clear = async () => Object.keys(localStorage).filter(key => key.startsWith(LOCALSTORAGE_KEY_PREFIX)).forEach(key => localStorage.removeItem(key));
} else {
const store = new IDBStore('github-fetcher', 'request-cache')
this._cache.set = async (key, value) => idbSet(key, value, store);
Expand Down

0 comments on commit a742b97

Please sign in to comment.