When to use Memorycache?

Asked

Viewed 177 times

6

I would like a real example, not necessarily a code, on when use the MemoryCache on Web systems. What types of situation ask for its use?

A little context: I participated in an interview where they asked me this question and I could not answer, because I never did any kind of caching. In the systems where I have already given maintenance practically all queries were made directly in the database. Although the volume of information was large, we never had problems with performance, and what we had was solved with indexes or other solutions directly in the bank, but never in the application itself.

  • 1

    good day, usually in applications where they return a large mass of user access account information data where they do not have the accuracy to go in the bank at all times to be seeking user information, we may be using a Memorycache to be storing the data in the application

1 answer

5


The question is a little broad, but come on.

I imagine you’ve read the documentation of him. At least that’s what the programmer does when he sees something new that he doesn’t know and wants to know more. I’m not going to say what’s already there, it doesn’t seem to be the focus.

Cache is one of the most important and most commonly used strategies to make data be accessed faster. Caching is simpler than people realize. You do a calculation and you cache it in a variable. Do you want it simpler than that? Of course, here we’re talking about a slightly more sophisticated mechanism.

Cache is extremely complicated as it comes out of the trivial, especially when needed decide on his invalidation. But caching is just a way to deliver information faster than the traditional way, no matter how much. An example would be the memoisation which is the basic design standard used in much of the cache engines.

You can have multiple levels of caching in and around the application. You may have something that is part of your application or is done by third parties on infrastructure that you use directly or indirectly, something hardware or software. Knowing which ones to use and which ones are exaggeration is an art. Some you do not choose, exist and good. As it is very complicated to make certain caches it is better to use some mechanism ready in most cases.

So the question is lower, is when to use the cache. When it is needed then the MemoryCache should be your choice (but there may be other levels of caching outside your application). It will be correct, has the form that is probably more efficient, competition controls and especially now must have one or more disability strategies that work reasonably well in most situations. And one of the most important things is to have a monitoring to invalidate on demand, which is one of the most consistent invalidations that exists (with advantages and disadvantages).

The real example depends on the situation, so it is very difficult to set an example. Anyway no matter the mechanism, it is important to understand the whole process of software development to absorb about the need for cache. There is no magic answer, except that you should use it when you need more performance and a test show that the cache partially or totally solves. There is no situation that can be said to always use or should never use, even because the same problem can change if the volume changes.

There are problems that cache helps little or nothing or disturbs. If you have rare access to the same given the cache is only a hindrance. Only the repeat pattern of access to the same data over and over gives you a clear advantage.

Already answered about for PHP, is still valid here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.