...

/

Adding Caching

Adding Caching

Implement caching in the Django application for optimized data retrieval.

In software computing, caching is the process of storing copies of files in a cache so they can be accessed more quickly. A cache is a temporary storage location that stores data, files, and information concerning software that is regularly requested.

A great example and explanation of caching comes from Peter Chester, who asked the audience at one of his speeches: “What’s 3,485,250 divided by 23,235?” Everyone fell silent for a moment, but someone pulled a calculator and yelled out the answer, “150!” Then, Peter Chester asked the same question again, and this time, everyone was able to answer the question immediately.

This is a great demo of the concept of caching: The computation is only done once by the machine and then saved in quick memory for faster access.

It is a concept used widely by companies, especially social media websites where millions of users access the same posts, videos, and files. It would be very inefficient to querying the database whenever millions of people want to access the same information. For example, if a tweet is gaining traction on Twitter, it is automatically moved to cache storage for quick access. And, if you have an influencer such as Kim Kardashian posting a picture on Instagram, you should expect a lot of requests for this picture. Caching can be useful here to avoid thousands of queries on the database.

To summarize, caching brings the following benefits:

  • Reduced load time

  • Reduced bandwidth usage

  • Reduced SQL queries on databases

  • Reduced downtime

Now that ...