Projects use the MVC3 framework, pages use caching to relieve server pressure, and use cache profile settings CacheProfile
<system.web> ...... <!--other configuration nodes--<caching> <outputCacheSettings> <outputCacheProfiles> <add Name="index" duration=" enabled=" True" location="Client" varybyparam="City,type "/> </outputCacheProfiles> </outputCacheSettings> </caching > </system.web>
Using the OutputCache attribute on an action
[OutputCache (cacheprofile="Index")] PublicActionResult Index (stringCitystringtype) {viewbag.city=City ; Viewbag.type=type; Viewbag.message="welcome to the ASP. NET mvc!"; varQuerylist = list. Where (c = c.city = =City ); returnView (querylist); }
After the configuration and code finishes, run the page. The first page Returns 200 status, press F5 after the page or return 200 of the status code, what happened, the page is not actually cached ....
Originally this is a bug of ASP, how to solve it? We can Nega Response.Cache.SetOmitVaryStar (true) in the action method; The cache does not take effect when the property location in the test discovery configuration information is configured as "Client", and the page cannot be cached .... This is too much of a hole.
The page cannot be cached until the property location in the configuration information is configured as "ServerAndClient".
<system.web> ...... <!--other configuration nodes--><caching> <outputCacheSettings> <outputCacheProfiles> <add name=" Index " duration= " "enabled="true"location=" ServerAndClient "varybyparam="city,type "
</outputCacheProfiles> </outputCacheSettings> </caching> </system.web>
PublicActionResult Index (stringCitystringtype) { Response.Cache.SetOmitVaryStar ( true); Viewbag.city=City ; Viewbag.type=type; Viewbag.message="welcome to the ASP. NET mvc!"; varQuerylist = list. Where (c = c.city = =City ); returnView (querylist); }
ASP. NET MVC 3 OutputCache issues to be aware of using page caching