ASP. NET MVC 3 OutputCache issues to be aware of using page caching

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.