This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17043|Reply: 0

[ASP.NET] mvc cache the correct usage of the OutputCache property VaryByParam

[Copy link]
Posted on 2/8/2017 4:18:55 PM | | | |



The OutputCache filter is used as a cache to save users time and resources to access the application and improve the user experience, but I couldn't find any effect on it. Keep it as a note. The OutputCacheAttribute class has the following properties:

Attribute name
type
description
Duration
int
The cache time, measured in seconds, can theoretically be very long, but in practice, when system resources are tight, the cache space will still be reclaimed by the system.
VaryByParam
string
For example, when the "ID" field changes, the cache needs to be changed (the original cache can still be retained), then VaryByParam should be set to "ID". Here you can set the following values:
* = Changes the cache when any parameter changes.
none = does not change the cache.
with a semicolon"; "List of field names for the interval = changes the cache if the fields in the list change.
locatio{filter}n
OutputCachelocatio{filter}n
Where to put cached data. The default is Any, and the other values are Client, Downstream, Server, None, and ServerAndClient
NoStore
bool
Secondary storage for deciding whether to block sensitive information.


Let's focus on the VaryByParam property, which actually means that the url changes the cache according to the name of those parameters.

The default value of VaryByParam is *, which means that any parameter name can change the cache...



The above is the cache I set, only the URL connection parameter name is dir, sort, sort_model, the cache changes

For example, when the value value of the dir parameter changes, a cache will be regenerated, and the original cache will not be deleted!





Previous:mvc identity filter ActionFilterAttribute is used
Next:Split parameter StringSplitOptions.RemoveEmptyEntries
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com