Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getLocalStorageInstance(): Promise {
if (!process.browser) {
return Promise.resolve(null);
}
try {
const shouldPurge = await shouldPurgeCache();
if (!shouldPurge) {
return localforage;
}
await localforage.clear();
await localforage.setItem('version', APP_VERSION);
return localforage;
} catch (error) {
console.error(error, 'localforage: ');
await localforage.clear(); // cache is possibly full so lets clear it
return localforage;
}
}
import localforage from 'localforage'
import { from, Observable } from 'rxjs'
import { first } from 'rxjs/operators'
import * as sourcegraph from 'sourcegraph'
const USE_PERSISTENT_MEMOIZATION_CACHE = true
if (!USE_PERSISTENT_MEMOIZATION_CACHE) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
localforage.clear()
}
interface Cache {
get(key: string): Promise
set(key: string, value: T | Promise): Promise
delete(key: string): Promise
}
const createMemoizationCache = (): Cache => {
const map = new Map>()
const cache: Cache = {
get: (key): Promise => {
const localValue = map.get(key)
if (localValue !== undefined) {
return localValue
}
localforage.INDEXEDDB,
'memoryDriver',
localforage.LOCALSTORAGE,
localforage.WEBSQL,
localForageDrivers
];
for (const driverName of DRIVERS) {
console.log('Test ', driverName);
try {
await localforage.setDriver(driverName);
console.log('A');
await localforage.setItem('hello', 'world');
console.log('B');
const x = await localforage.getItem('hello');
console.log('got ', x);
await localforage.clear();
console.log('C');
} catch (error) {
console.log('Error', error);
}
}
}
export const clearDatabase = async () => {
return localforage.clear();
};
export function clearIndexedDBCache() {
return localforage.clear();
}
export const clearLocalDatabase = () => localForage.clear();
clear() {
return localforage.clear();
}
}
public async clear() {
return localforage.clear();
}
"associated with wed?", function (result) {
if (!result)
return;
localforage.clear().then(function () {
me._controller.scope().$apply('refresh()');
});
});
});
IndexedDB.clear = function () {
return localforage.clear();
};