Giter Club home page Giter Club logo

catbox-disk's People

Contributors

eyepulp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

catbox-disk's Issues

TTL always returned as NaN

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.

can't get the simplest example to work

I am using the following code (combining the Hapi caching tutorial with the catbox-disk documentation) to get started with catbox-disk before I graduate to something more advanced

const Hapi = require('hapi');
const Disk = require('catbox-disk');

const server = new Hapi.Server({
	cache : [{
			name      : 'diskCache',
			engine    : Disk,
			cachePath : '/some/existing/dir',
			cleanEvery: 3600000,
			partition : 'cache'
	}]
});

const start = async () => {

	const add = async (a, b) => {
		await Hoek.wait(1000);   // Simulate some slow I/O
		return Number(a) + Number(b);
	};

	const sumCache = server.cache({
		cache: 'diskCache',
		expiresIn: 10 * 1000,
		generateFunc: async (id) => {
			return await add(id.a, id.b);
		},
		generateTimeout: 2000
	});

	server.route({
		path: '/add/{a}/{b}',
		method: 'GET',
		handler: async function (request, h) {
			const { a, b } = request.params;
			const id = `${a}:${b}`;

			return await sumCache.get({ id, a, b });
		}
	});

	await server.start();

	console.log('Server running at:', server.info.uri);
};

start();

I get the following error

/Users/punkish/Projects/catbox/node_modules/hapi/lib/config.js:19
throw new Error(Invalid ${type} options ${message.length ? '(' + message.join(' ') + ')' : ''} ${result.error.annotate()});
^

Error: Invalid cache options [
{ [1]
"name": "diskCache",
"cachePath": "/Users/punkish/Projects/catbox/diskCache",
"cleanEvery": 3600000,
"partition": "cache",
"engine" [2]: function Disk(options) {\n\n Hoek.assert(\n this.constructor === internals.Connection,\n 'Disk cache client must be instantiated using new'\n );\n\n const settings = Hoek.applyToDefaults(internals.defaults, options);\n\n Hoek.assert(settings.cachePath, 'Missing cachePath value');\n Hoek.assert(\n settings.cleanEvery === parseInt(settings.cleanEvery, 10),\n 'cleanEvery is not an integer'\n );\n\n this.settings = Object.assign({}, internals.defaults, options);\n this.isConnected = false;\n this.cacheCleanerTimeout = null;\n return this;\n}
}
]

[1] "0" must be a Function
[2] "engine" must be an object
at Object.exports.apply (/Users/punkish/Projects/catbox/node_modules/hapi/lib/config.js:19:15)
at module.exports.internals.Core._createCache (/Users/punkish/Projects/catbox/node_modules/hapi/lib/core.js:172:26)
at module.exports.internals.Core._initializeCache (/Users/punkish/Projects/catbox/node_modules/hapi/lib/core.js:140:18)
at new module.exports.internals.Core (/Users/punkish/Projects/catbox/node_modules/hapi/lib/core.js:107:14)
at new module.exports (/Users/punkish/Projects/catbox/node_modules/hapi/lib/server.js:22:18)
at Object. (/Users/punkish/Projects/catbox/index.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.