Files
kami-parse-server/src/Adapters/Cache/LRUCache.js
Florent Vilmart d83a0b6808 Use Prettier JS (#5017)
* Adds prettier

* Run lint before tests
2018-09-01 13:58:06 -04:00

30 lines
497 B
JavaScript

import LRU from 'lru-cache';
import defaults from '../../defaults';
export class LRUCache {
constructor({ ttl = defaults.cacheTTL, maxSize = defaults.cacheMaxSize }) {
this.cache = new LRU({
max: maxSize,
maxAge: ttl,
});
}
get(key) {
return this.cache.get(key) || null;
}
put(key, value, ttl = this.ttl) {
this.cache.set(key, value, ttl);
}
del(key) {
this.cache.del(key);
}
clear() {
this.cache.reset();
}
}
export default LRUCache;