* Adding Caching Adapter, allows caching of _Role and _User queries.
This commit is contained in:
37
src/cache.js
37
src/cache.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user