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

Question: Is it OK to use _cache as general purpose cache? #954

Closed
paullang opened this issue Jul 6, 2013 · 4 comments · Fixed by #994
Closed

Question: Is it OK to use _cache as general purpose cache? #954

paullang opened this issue Jul 6, 2013 · 4 comments · Fixed by #994
Assignees
Labels
feature New functionality or improvement support Questions, discussions, and general support
Milestone

Comments

@paullang
Copy link
Contributor

paullang commented Jul 6, 2013

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) {
...
});
@hueniverse
Copy link
Contributor

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.

@paullang
Copy link
Contributor Author

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.

@hueniverse
Copy link
Contributor

Yeah, just use another prefix character that's supported by the DBs we use.

@ghost ghost assigned hueniverse Jul 20, 2013
@geek geek closed this as completed in #994 Jul 22, 2013
@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 20, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement support Questions, discussions, and general support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants