mirror of
https://github.com/apache/superset.git
synced 2024-09-20 04:29:47 -04:00
31 lines
728 B
TypeScript
31 lines
728 B
TypeScript
|
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));
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
global.caches = new CacheStorage();
|