5

I have two options for implementing caching in my web application. I can either add a Varnish cache outside of my application code, and cache the responses on a per-request URL basis, or I can use an in-memory cache like memcached to store the results of database accesses.

I am having a hard time choosing between these two implementations. I think adding Varnish results in less code (don't have to add logic around whether to cache a database result or not), but there is a little more overhead in terms of infrastructure to add the Varnish caching layer.

What are other benefits of using one solution over the other? And are there other important things I haven't considered?

  • 1
    Have you done some performance measurements to identify which part of the system is slowing things down? – Robert Harvey Dec 8 '16 at 23:49
1

You haven't told what your rationale is behind needing a cache.

Having both kinds of cache would be the ideal case though since both speed things up in their own way.

I would suggest you try varnish first and see if the improvements it provides to be satisfactory(most of the time, it is).

If it doesn't, then try app-level caching and try to cache stuff based on their effect on the performance of the system(So that means you'll have to profile your application thoroughly under different kinds of loads), then try one aspect at a time in the order of effect on performance(first authentication and session related info,then Db results, and so on). For every addition re-profile your system and compare the results.

You should also try to see if you can improve the code(if possible) in cases where it is the code(and not the IO that's slowing things down).

Once you do this you should be able to find the pulse of the system, and you would be able to isolate and improve the performance of individual cogs without causing complexity.Most importantly,STOP when you find your balance-The point where the work exceeds the potential gains obtained.

  • While YAGNI is a good principle, introducing model caching in an established application would be a tremendous task. – Basilevs Dec 17 '16 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.