This article collects some information about why caching is needed in the project, how to use it, and how to consider the design of the cache in real-world development.
Why do we need to discuss caching?
Caching is a problem that must be considered in a medium-sized system. In order to avoid each request to access the background resources (such as the database), we generally consider some of the updates are not very frequent, can be reused data, in a certain way to temporarily save, the subsequent requests can be directly accessed by the situation of these saved data. This mechanism is called a caching mechanism.
Depending on the location of the cache, the zone can be divided into:
1. Client cache (cached on the user's client, e.g. browser)
2, the server is out of stock (cached in the server, can be slow in memory, can also be slow to exist in the file, and can be further differentiated into local cache and distributed cache two)
It should be said that the design of the cache is a more complex learning, the main issues to consider include:
1. Do you want to cache?
2. What data to cache?
3. How much data to cache?
4, how long to cache?
5. How to update the cache (manual or automatic)
6. Where is the cache placed?
This article takes a look at the above questions about how to use the caching feature in a real-world project.
Common caching feature support is shown in the following areas:
1. You can define the output cache (page cache) directly above the controller. Control cache? )
2, through the method of caching policy, flexibly define the settings of the cache (new function)
3. Support cache dependencies to be notified when external resources change, and update the cache
4, support the use of the cache API, but also support some third-party caching schemes (such as distributed cache)
For the common MVC framework, suppose there is an entity class employee, we can change the employee additions and deletions
1. Using Output caching
For example, we have
Reference link: Talk about the design of cache function in MVC Project
Discussion on the design of cache function in MVC Project