Files
kami-parse-server/src/cache.js
2016-02-26 22:48:53 -08:00

36 lines
636 B
JavaScript

/** @flow weak */
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
};