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?

Tulains Córdova
39.6k13 gold badges102 silver badges157 bronze badges
asked Dec 8, 2016 at 21:48
1
  • 1
    Have you done some performance measurements to identify which part of the system is slowing things down? Commented Dec 8, 2016 at 23:49

1 Answer 1

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.

answered Dec 9, 2016 at 9:47
1
  • While YAGNI is a good principle, introducing model caching in an established application would be a tremendous task. Commented Dec 17, 2016 at 14:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.