Closed jholland918 closed 10 years ago
What's the actual problem you are trying to solve?
I have a default config that is initialized with production values like host, port, database, route expiresIn, etc. Then if the environment is development I override the settings like so:
if (config.env == 'development') {
//...
config.route.foo.expiresIn = 0;
//...
}
Then I use the config option like this:
server.route({
method: 'GET',
path: '/foo',
config: {
cache: {
expiresIn: config.route.foo.expiresIn
},
handler: function (request, reply) {
reply({
foo: 'bar'
});
}
}
});
I'm just getting started with hapi and I initially thought I had to add a cache to every route and I didn't see the server.cache
option until after I submitted this request, so I'm now using that. I suppose that's the side effect from trying to learn a new library so late at night/early morning. :)
Well, you can't do that - add a cache
config that specifies no caching. Just change your override to set the entire cache
object to null
.
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.
Using server.route.config.cache.expiresIn = 0 in hapi causes the following error: "Error: Rule must include one of expiresIn or expiresAt but not both {"expiresIn":0}".
The call to Catbox.Policy() here https://github.com/spumko/hapi/blob/master/lib/route.js#L84 passes an undefined expiresAt attribute in hapi's route.js code. My first thought was to check for undefined before calling Catbox.Policy() in route.js but I found that Catbox.Policy is similarly called with both expiresIn and expiresAt in hapi's pack.js so maybe there's some kind of convention that I'm not sure about so I ended up changing the assert instead.
Of course if you trigger the code in pack.js by running "var cache = server.cache('countries', { expiresIn: 0 });" the error is not generated because of the truthy condition (https://github.com/spumko/hapi/blob/master/lib/pack.js#L669) that sets the settings parameter. The settings parameter ends up not getting any attribute added to it which doesn't throw an error and probably behaves as expected when setting expiresIn = 0 anyway.