Files
kami-parse-server/src/Adapters/Cache/InMemoryCacheAdapter.js

37 lines
646 B
JavaScript
Raw Normal View History

import {LRUCache} from './LRUCache';
export class InMemoryCacheAdapter {
constructor(ctx) {
this.cache = new LRUCache(ctx)
}
get(key) {
return new Promise((resolve) => {
2016-12-07 15:17:05 -08:00
const record = this.cache.get(key);
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;