This commit is contained in:
2020-05-25 16:07:30 +03:00
parent 0753359f07
commit 13971100cf
55 changed files with 32279 additions and 6964 deletions

34
api/src/util/Cache.js Normal file
View File

@@ -0,0 +1,34 @@
import Cacheman from 'cacheman';
import { CACHE } from './Constants';
const formatKey = (name) => {
if (!name) {
throw Error('No number plate specified');
}
return `${CACHE.PREFIX.plate}${name}`;
};
class Cache {
manager;
constructor() {
this.manager = new Cacheman({
ttl: CACHE.ttl,
engine: CACHE.engine,
tmpDir: CACHE.directory,
});
}
async get(name) {
return this.manager.get(formatKey(name));
}
save(name, data) {
if (!data) {
throw Error(`No data for caching car ${name}`);
}
this.manager.set(formatKey(name), data);
}
}
export default Cache;