Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is cache profile?

I encountered with it while I was reading this article from MSDN documentation. I am pretty newbie about caching, in fact, one of the first articles that I read about caching. Can you explain me simply?

like image 455
Orhun Avatar asked Nov 28 '25 00:11

Orhun


1 Answers

In short its a caching profile that you can set in the web.config instead of having to apply the settings to every Action or Controller you want to use the cache settings with:

In web.config you specify options for the cache profile:

  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="cp1" duration="30" location="Any" varyByHeader="user-agent" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
  </system.web>

Then anywhere you want to use the profile you can just use e.g.

[OutputCache(CacheProfile="cp1")]
public ActionResult Index() {
     //...
}

Above example taken from Apress Pro ASP.NET MVC 5 Platform by Adam Freeman. I recommend it as a good read.

like image 131
James P Avatar answered Nov 29 '25 23:11

James P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!