Question: Is it OK to use _cache as general purpose cache?
I need to do some general purpose caching from my Hapi based application. Since I already have Hapi configured with an open cache connection to Redis, I would prefer to just reuse that.
I confirmed the following will work from my request handler, but is this usage frowned upon since it is not a part of the public API?
request.server.pack._cache.set({segment: 'someKey', id: 'someId'}, 'someValue', ttl, function (err) {
...
});
It's not. If you are using the plugin interface, you can use this:
https://github.com/spumko/hapi/blob/master/docs/Reference.md#plugincacheoptions
Otherwise, we can add this interface to the server itself.
Personally, I would just create plugins. They are awesome.
Plugins are awesome and I'll be taking that route.
I created a fun little proof of concept plugin to teach myself how to create my own public plugins as well as how to call the cache client from within a plugin. I also learned a little about lab and server.inject in the process. https://npmjs.org/package/deadbox
I can see value in plugins when properly engineering an application and when sharing generic public plugins, but for private logic, wrapping a local node library can be an extra barrier to entry if somebody new to the framework is just trying to hack together something quickly. If you do add an interface for cache to the server, I suppose you'll need to prepend something to the key name to avoid key name collisions.
Yeah, just use another prefix character that's supported by the DBs we use.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.