I was starting today to look on different approaches and techniques that are used in scalable web or non web applications. One technique used in many large systems is simply called “memory cache”. It means that data are cached in memory so the data will not be queried again.
Cache and memory cache exists for a long time; even the hardware parts link hard disks cd units have some sort of memory cache.
Why memory cache becomes so important when we talk about web applications? It’s simple. Because web applications happens to fulfill thousands of requests simultaneously. Or sometimes they have to. It’s obvious that keeping the data into memory and reuse it the next time you need it it will improve the performance. And it looks very simple. At the first view simple hashmap would do the job, unless…
There a few facts we need to be consider in real world:
- What happens when the database is updated?
- In most cases a web application create a thread for each http request. The same thing happens in java of php or other languages. The creation of the threads is handled by the web server, web container, and not by the code we write.
- The scalable applications run distributed on multiple servers. If one application change the database, the cache system should be informed on all the machines.