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

@@ -1,35 +1,4 @@
/** @flow weak */
import {InMemoryCache} from './Adapters/Cache/InMemoryCache';
export function CacheStore<KeyType, ValueType>() {
let dataStore: {[id:KeyType]:ValueType} = {};
return {
get: (key: KeyType): ValueType => {
return dataStore[key];
},
set(key: KeyType, value: ValueType): void {
dataStore[key] = value;
},
remove(key: KeyType): void {
delete dataStore[key];
},
clear(): void {
dataStore = {};
}
};
}
const apps = CacheStore();
const users = CacheStore();
//So far used only in tests
export function clearCache(): void {
apps.clear();
users.clear();
}
export default {
apps,
users,
clearCache,
CacheStore
};
export var AppCache = new InMemoryCache({ttl: NaN});
export default AppCache;