Using user-level caching

User-level caching is another level of caching that can prove to be of quite a lot of use. Imagine querying the personal details of the user from the database every time the user moves from one page to another. This would not only be inefficient, but would also penalize during high-load situations, when the response times of the database could be so high that a request could just time out and the user would not be able to log in to the application until the overall load reduced.

So, is there anything that can help here?

The answer to this is user-level caching. When we know that some data is specific to the user and is not critical to security, we can simply load it once from the database and save it on the user side. This can be achieved by implementing cookies or creating temporary files on the client side. These cookies or temporary files store non-confidential data about the user, such as user ID or username, or other non-important data, such as the name of the user.

Whenever the application wants to load this data, instead of going to the database directly, it first checks whether the user has this data available at their end. If the data is found, then the data is loaded from there. If the data is not found on the user side, the request is made to the database, and the data is loaded from there, before being finally cached on the client side.

This kind of technique helps a lot when trying to reduce the impact of data loading that is specific to users and does not need to be refreshed from the database frequently.

There are much more sophisticated techniques for caching data by using key-value caching mechanisms, as we will see in later chapters, such as implementing in-memory caches using tools such as memcached, which can prove to be of great help when dealing with huge amounts of data. However, this is beyond the scope of this book, due to the complexity of the topics involved, which can span several hundreds of pages.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.40.189