2020-03-31 20:08:59 -04:00
|
|
|
import { configure } from '@superset-ui/translation';
|
|
|
|
|
|
|
|
configure();
|
|
|
|
|
2019-04-02 13:45:07 -04:00
|
|
|
const caches = {};
|
|
|
|
|
|
|
|
class Cache {
|
|
|
|
cache: object;
|
|
|
|
constructor(key: string) {
|
|
|
|
caches[key] = caches[key] || {};
|
|
|
|
this.cache = caches[key];
|
|
|
|
}
|
|
|
|
match(url: string): Promise<Response | undefined> {
|
|
|
|
return new Promise((resolve, reject) => resolve(this.cache[url]));
|
|
|
|
}
|
|
|
|
delete(url: string): Promise<boolean> {
|
|
|
|
delete this.cache[url];
|
|
|
|
return new Promise((resolve, reject) => resolve(true));
|
|
|
|
}
|
|
|
|
put(url: string, response: Response): Promise<void> {
|
|
|
|
this.cache[url] = response;
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CacheStorage {
|
|
|
|
open(key: string): Promise<Cache> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(new Cache(key));
|
|
|
|
});
|
|
|
|
}
|
2019-07-23 19:03:40 -04:00
|
|
|
delete(key: string): Promise<boolean> {
|
|
|
|
const wasPresent = key in caches;
|
|
|
|
if (wasPresent) {
|
|
|
|
caches[key] = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(wasPresent);
|
|
|
|
}
|
2019-04-02 13:45:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
global.caches = new CacheStorage();
|