Reputation: 3278
I need to cache idempotent requests in Redis with some expiration time. The tutorials featured on Hapi's website favors catbox.
The tutorial recommends using server methods for retrieving data. I couldn't understand the point of that approach. I simply need caching the response data with same URL. What's the point of creating a new wrapper function?
Also, I'm running my server with Nginx reverse proxy. It seems to have response caching functionality, should I use that, if I should how could I?
Thank you.
Upvotes: 0
Views: 692
Reputation: 4349
I would say, if something is possible to do with Nginx, and you can figure out how to do it, then use Nginx. It tends to be very fast. But, it is usually harder to do a task in Nginx config files than it is in JavaScript. It's hard for me to imagine that you need to eek out that extra bit of performance, as Redis is also very fast. If it were me, I would use Catbox with Redis.
If I understand the question, the point of the wrapper function is to deal with creating a key to store and lookup the cached value, and deal with expiration.
If you want, I think this is a config file for how to do it with Nginx:
http {
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m
inactive=24h max_size=1g;
server {
location / {
proxy_pass http://1.2.3.4;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
}
}
Upvotes: 1