vsm-dictionary-cacher
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "vsm-dictionary-cacher", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Wrapper around a VSM-dictionary, that manages a cache of string-match results", | ||
@@ -27,9 +27,9 @@ "main": "src/VsmDictionaryCacher.js", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^5.3.0", | ||
"mocha": "^5.0.5", | ||
"chai": "^4.2.0", | ||
"eslint": "^5.8.0", | ||
"mocha": "^5.2.0", | ||
"sinon": "^4.5.0", | ||
"vsm-dictionary-local": "^2.3.0" | ||
"vsm-dictionary-local": "^2.4.0" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -217,7 +217,7 @@ # vsm-dictionary-cacher | ||
to `clearCache()` (see below). | ||
- Note: this is handled in `getEntryMatchesForString()`, not | ||
in `getMatchesForString`, because the latter may still add 'extra' matches | ||
- Note: this is handled in `getEntryMatchesForString()`, not in | ||
`getMatchesForString()`, because the latter may still add 'extra' matches | ||
(refTerm/number/fixedTerm), other than the 'entry'-type matches. | ||
- Example 1: after a call for "i" would give no entry-matches (and "i" | ||
ends up in cacheEmpties), a subsequent call for "it" should still | ||
ends up in the 'cacheEmpties'), a subsequent call for "it" should still | ||
return "it" as a refTerm-match. | ||
@@ -235,3 +235,3 @@ (Note that a refTerm only matches for a full, not partial, string match). | ||
- `clearCache()`: | ||
This removes all data from the cache layer, including e.g the list used by | ||
This removes all data from the cache layer, including e.g. the list used by | ||
`predictEmpties`. |
@@ -6,8 +6,8 @@ const { callAsync, /*getNowTime,*/ deleteOldestCacheItem } = require('./util'); | ||
describe('helpers/util.js', function() { | ||
describe('callAsync()', function() { | ||
describe('helpers/util.js', () => { | ||
describe('callAsync()', () => { | ||
var f = (a, b, cb) => cb(null, a * b); | ||
var count = 0; | ||
it('calls a function on the next event loop', function(cb) { | ||
it('calls a function on the next event loop', cb => { | ||
callAsync(f, 2, 5, (err, ans) => { | ||
@@ -23,5 +23,5 @@ expect(err).to.equal(null); | ||
describe('deleteOldestCacheItem()', function() { | ||
describe('deleteOldestCacheItem()', () => { | ||
it('removes the item with the oldest (smallest) `lastAccessed` property ' + | ||
'from a cache ', function() { | ||
'from a cache ', () => { | ||
var cache = { | ||
@@ -28,0 +28,0 @@ a: { value: 1, lastAccessed: 50 }, |
@@ -98,3 +98,3 @@ /* | ||
* - All dictInfos received from any query are stored here, by dictID key. | ||
* - For dictInfos that it expected but did not recieve, and which are | ||
* - For dictInfos that it expected but did not receive, and which are | ||
* thus non-existent, it stores a `'-'`. | ||
@@ -347,5 +347,5 @@ * E.g.: `{ dictID1: {dictID: dictID1, name: ..}, dictID2: '-', .. }`. | ||
* based on `options`. These types are: | ||
* - Request for all dictInfos. --> [We call this a 'req-for-IDs']. | ||
* - Request based on a list of dict-names (this bypasses the cache). | ||
* - Request based on a list of dictIDs. --> [We call this a 'req-for-all']. | ||
* - Request for all dictInfos. --> [We call this a 'req-for-all']. | ||
* - Request based on a filter other than for dictIDs (bypasses the cache). | ||
* - Request based on a list of dictIDs. --> [We call this a 'req-for-IDs']. | ||
*/ | ||
@@ -355,3 +355,3 @@ getDictInfos(options, cb) { | ||
// Request that use a filter other than for dictIDs, bypass the cache; | ||
// Requests that use a filter other than for dictIDs, bypass the cache; | ||
// but any valid result they receive will still update the cache. | ||
@@ -358,0 +358,0 @@ if (!options.filter.id ) { |
@@ -148,3 +148,3 @@ const cacher = require('./VsmDictionaryCacher'); | ||
it('lets the first call to getMatchesForString() pass through, ' + | ||
'to let the parent class query', cb => { | ||
'to let the parent class query', cb => { | ||
dict.getMatchesForString('a', {}, (err, res) => { | ||
@@ -159,3 +159,3 @@ calledMO.should.equal(1); | ||
it('...but uses cached results for a second call ' + | ||
'with same arguments', cb => { | ||
'with same arguments', cb => { | ||
dict.getMatchesForString('a', {}, (err, res) => { | ||
@@ -764,12 +764,12 @@ calledMO.should.equal(0); | ||
it('queries for dict-name, but does not use cache for lookup (but does ' + | ||
'put the result in it); and sorts by dictID', cb => { | ||
dict.getDictInfos({filter: {name: ['Name Y', 'Name Z']}}, (err, res) => { | ||
it('does not use cache for queries with filter other than dictID; ' + | ||
'but does put the result in the cache', cb => { | ||
dict.getDictInfos({filter: {xyz: 'ignored'}}, (err, res) => { | ||
expect(err).to.equal(null); | ||
res.should.deep.equal({ items: [di4, di5] }); | ||
Object.keys(dict.cacheDI).length.should.equal(2); // Filled the cache. | ||
res.should.deep.equal({ items: [di1, di2, di3, di4, di5] }); | ||
Object.keys(dict.cacheDI).length.should.equal(5); // Filled the cache. | ||
dict.getDictInfos({filter:{name:['Name Y', 'Name Z']}}, (err, res) => { | ||
dict.getDictInfos({filter: {xyz: 'ignored'}}, (err, res) => { | ||
expect(err).to.equal(null); | ||
res.should.deep.equal({ items: [di4, di5] }); | ||
res.should.deep.equal({ items: [di1, di2, di3, di4, di5] }); | ||
calledDI.should.equal(1); // I.e. it queried; did not use the cache. | ||
@@ -781,3 +781,3 @@ cb(); | ||
it('sort cache-hits either by ID or by name', cb => { | ||
it('sorts cache-hits either by ID or by name', cb => { | ||
dict.getDictInfos({ filter: { id: ['E', 'D', 'C'] } }, (err, res) => { | ||
@@ -784,0 +784,0 @@ res.should.deep.equal({ items: [di3, di4, di5] }); |
100771
7
1968