Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cacheKeyForTree(treeType) {
let methodsToValidate = methodsForTreeType(treeType);
let cacheKeyStats = heimdall.statsFor('cache-key-for-tree');
// determine if treeFor* (or other methods for tree type) overrides for the given tree
let modifiedMethods = methodsToValidate.filter(methodName => this[methodName] !== addonProto[methodName]);
if (modifiedMethods.length) {
cacheKeyStats.modifiedMethods++;
cacheKeyLogger.info(`Opting out due to: modified methods: ${modifiedMethods.join(', ')}`);
return null; // uncacheable
}
// determine if treeForMethods overrides for given tree
if (this.treeForMethods[treeType] !== DEFAULT_TREE_FOR_METHODS[treeType]) {
cacheKeyStats.treeForMethodsOverride++;
cacheKeyLogger.info('Opting out due to: treeForMethods override');
return null; // uncacheable
}
obj[name] = function() {
const stats = heimdall.statsFor('async-disk-cache');
const metrics = stats[name] = stats[name] || new Metric();
metrics.start();
let result;
let didError = true;
try {
result = fn.apply(this, arguments);
didError = false;
} finally {
if (didError) {
metrics.stop();
}
}
getItem(key) {
let addonTreeCacheStats = heimdall.statsFor('addon-tree-cache');
let cachedValue = this.__cache[key];
if (cachedValue) {
addonTreeCacheStats.hits++;
treeCacheLogger.info(`Cache Hit: ${key}`);
return cachedValue;
} else {
addonTreeCacheStats.misses++;
treeCacheLogger.info(`Cache Miss: ${key}`);
return null;
}
},
setItem(key, value) {
let hasValue = !!value;
heimdall.statsFor('addon-tree-cache').adds++;
treeCacheLogger.info(`Cache Add: ${key} - ${hasValue}`);
this.__cache[key] = value;
},