Caching is one of the optimizations that can have a greater impact on the performance of a site. By caching responses and data, you do not have to fetch them again, process them, and send them to the client. Let's look at a couple of ways by which we can achieve this.
Caching data
By caching your data, you do not need to go and retrieve it again and again whenever it is needed. You need to consider a number of aspects:
- How long will it be kept in the cache?
- How can you invalidate the cache if you need to do so?
- Do you need it to be distributed across different machines?
- How much memory will it take? Will it grow forever?
There are usually three ways to specify the cache duration:
- Absolute: The cache will expire at a predefined point in time.
- Relative: The cache will expire some time after it is created.
- Sliding: The cache...