Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #34

Merged
merged 3 commits into from Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -55,7 +55,7 @@ module.exports = function hashForDep(name, dir, _hashTreeOverride, _skipCache) {

var heimdallNode = heimdall.start(heimdallNodeOptions, HashForDepSchema);

if (CACHE.has(key)) {
if (skipCache === false && CACHE.has(key)) {
logger.info('cache hit: %s', key);
hash = CACHE.get(key);
} else {
Expand All @@ -73,7 +73,10 @@ module.exports = function hashForDep(name, dir, _hashTreeOverride, _skipCache) {
update(inputHashes).digest('hex');

logger.info('cache miss: %s, paths: %d, took: %dms', key, heimdallNode.stats.paths, Date.now() - start);
CACHE.set(key, hash);

if (skipCache === false) {
CACHE.set(key, hash);
}
}

heimdallNode.stop();
Expand Down
4 changes: 2 additions & 2 deletions lib/cache-key.js
@@ -1,8 +1,8 @@
'use strict';
var crypto = require('crypto');

module.exports = function cacheKey(name, dir, _hashTreeOverride) {
var value = name + 0x00 + dir + 0x00 + (typeof _hashTreeOverride === 'function');
module.exports = function cacheKey(name, dir) {
var value = name + 0x00 + dir;

return crypto.createHash('sha1').update(value).digest('hex');
};
25 changes: 25 additions & 0 deletions tests/hash-for-dep-test.js
Expand Up @@ -56,5 +56,30 @@ describe('hashForDep', function() {
expect(first).to.eql(second);
});

it('skips cache, when given a custom hashTreeOverride', function() {
expect(hashForDep._cache.size).to.eql(0);

var first = hashForDep('foo', fixturesPath, function() {});

expect(hashForDep._cache.size).to.eql(0);

var second = hashForDep('foo', fixturesPath, function() {});

expect(first).to.eql(second);
expect(hashForDep._cache.size).to.eql(0);

hashForDep._resetCache();

expect(hashForDep._cache.size).to.eql(0);

first = hashForDep('foo', fixturesPath, function() {});

expect(hashForDep._cache.size).to.eql(0);

second = hashForDep('foo', fixturesPath, function() {});

expect(hashForDep._cache.size).to.eql(0);
expect(first).to.eql(second);
});
});
});