Adding Caching Adapter, allows caching of _Role and _User queries (fixes #168) (#1664)

* Adding Caching Adapter, allows caching of _Role and _User queries.
This commit is contained in:
Blayne Chard
2016-05-18 12:12:30 +12:00
parent 5d887e18f0
commit 8c09c3dae1
18 changed files with 526 additions and 134 deletions

View File

@@ -0,0 +1,36 @@
import {InMemoryCache} from './InMemoryCache';
export class InMemoryCacheAdapter {
constructor(ctx) {
this.cache = new InMemoryCache(ctx)
}
get(key) {
return new Promise((resolve, reject) => {
let 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;