1
votes

I have a basic web app that given a url, hits a database, does some maths and returns some html. The result is a bit heavy to calculate but the results can be cached for sometime.

Is there any reason to add caching to my web application when I could just put a cache like Varnish in front of the web server?

2

2 Answers

4
votes

If it's possible for you to do in Varnish, and you know how to configure, tune, maintain and monitor Varnish, then I would recommend on doing it in Varnish. If however Varnish is new for you and you have experience with application-based caching, I would recommend that instead.

Doing a cache both in Varnish and in your app could potentially add another layer of complexity to your software stack, which is not desirable.

0
votes

Firstly, if you're not using Varnish yet, then you might want to wait to introduce it into your application stack until you really need it. It also depends on what you think is simplest to understand and handle for you: Learning how to cache in your app or introducing a new layer in your application stack. More layers equals more trouble, all other things equal.

Secondly, do it in the way that makes it easiest for you to control the cached copy, so that it does not get stale. If in your app you can cache it in such a way that it automatically expires when it needs to, and you do not have that ability with your setup or know how to do that in Varnish, then do the caching in the app.