@stuntman/server
Version:
Stuntman - HTTP proxy / mock server with API
35 lines • 1.12 kB
JavaScript
import { LRUCache } from 'lru-cache';
import sizeof from 'object-sizeof';
const DNS_CACHE_OPTIONS = {
max: 1000,
ttl: 1000 * 60 * 15,
allowStale: false,
updateAgeOnGet: false,
updateAgeOnHas: false,
};
const trafficStoreInstances = {};
const dnsResolutionCacheInstances = {};
export const getTrafficStore = (key, options) => {
if (!(key in trafficStoreInstances)) {
if (!options) {
throw new Error('initialize with options first');
}
trafficStoreInstances[key] = new LRUCache({
max: options.limitCount,
maxSize: options.limitSize,
ttl: options.ttl,
allowStale: false,
updateAgeOnGet: false,
updateAgeOnHas: false,
sizeCalculation: (value) => sizeof(value),
});
}
return trafficStoreInstances[key];
};
export const getDnsResolutionCache = (key) => {
if (!(key in dnsResolutionCacheInstances)) {
dnsResolutionCacheInstances[key] = new LRUCache(DNS_CACHE_OPTIONS);
}
return dnsResolutionCacheInstances[key];
};
//# sourceMappingURL=storage.js.map