mirusresearch/catbox-disk

TTL always returned as NaN

Closed this issue ยท 2 comments

Firstly, thanks for this great addition to catbox. We've been toying with writing our own, but stumbled across this implementation. ๐Ÿ‘

Everything appears to work really well, though the cache ttl on a cache.get appears to always return NaN. A really quick script I fumbled together below should replicate the issue.

var catbox = require('catbox'),
	catboxDisk = require('catbox-disk');

var cache = new catbox.Client(catboxDisk, {
	partition: 'test',
	cleanEvery: 360000,
	cachePath: './cache/'
});
cache.start(function(err){
	if(err){
		return console.error(err);
	}
	var key = {
		id: 'test-key',
		segment: 'test',
	};
	cache.set(key, {
		some: 'data',
		yes: 123
	}, 3000, function(err){
		if(err){ return console.error('Error setting cache').debug(err); }

		setInterval(function(){
			cache.get(key, function(err, data){
				console.log('cache results', err, data);
			});
		}, 1000);
	});
});

Looking in the .json file generated, the TTL seems to be set appropriately, but my results print

cache results null { item: { some: 'data', yes: 123 },
  stored: 2017-04-26T21:37:12.486Z,
  ttl: NaN }

before then being cleared. It appears the TTL is working as expected, but simply never being returned correctly.

Let me know if you need any further info.

Thanks @Cherry for the extremely well written issue. Found the issue and fixed it with a new test to verify. NPM version 2.0.8 is now published too.

Let me know if you run into any other issues.

Thanks very much for the quick resolution!