Caching in Simple

Moath Obeidat
2 min readAug 4, 2020

What is caching?

It's an effective way to improve the performance of a Web

application, By storing relatively static data in the cache and serving it

from the cache when requested, the application saves the time that would

be required to generate the data from scratch every time.

A simple summary

if the data isn’t in the cache bring it from DB, if it's in the cache bring

it from cache and don’t go to the DB.

In general

you will not notice that if you have a few records in your

DB, but what will happen if you have very big data like:-

Facebook, or twitter… etc, what will happen if 1000 users try to update their accounts page at the same time for example? your server may down! So there must be a solution for a case like this.

So what we need to use this solution?

Tools or libraries to cache our DB, and here is some :

X Cache, APC, ZEND Data Cache, Redis.

Caching have many types …

ex. Data caching, Fragment caching, Page caching, HTTP caching

So what will happen when our data is cached, but we have new data is released?

this will make our website out of date, because its display a cached data, and the new data can’t be seen to the users.

So the solution is to add some conditions on your code, like the duration of your cache time, ex. I want my data to be recached every 2 hours for example …

You can make a condition on your database query, so when there is a new entry on my data, reload the website to let users see the new data …

And there is a lot of conditions you can make, it depends on your case.

Caching in Simple

--

--