2016-05-18 12:12:30 +12:00
|
|
|
import {InMemoryCache} from './InMemoryCache';
|
|
|
|
|
|
|
|
|
|
export class InMemoryCacheAdapter {
|
|
|
|
|
|
|
|
|
|
constructor(ctx) {
|
|
|
|
|
this.cache = new InMemoryCache(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get(key) {
|
2016-11-24 15:47:41 -05:00
|
|
|
return new Promise((resolve) => {
|
2016-12-07 15:17:05 -08:00
|
|
|
const record = this.cache.get(key);
|
2016-05-18 12:12:30 +12:00
|
|
|
if (record == null) {
|
|
|
|
|
return resolve(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resolve(JSON.parse(record));
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
put(key, value, ttl) {
|
|
|
|
|
this.cache.put(key, JSON.stringify(value), ttl);
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
del(key) {
|
|
|
|
|
this.cache.del(key);
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
|
this.cache.clear();
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InMemoryCacheAdapter;
|