Sunday, 23 December 2018

What is CacheProfiles

We can specify  OutputCache settings in code. 

When we want to change the caching duration we need to change in the code that is in controllers action method and needs to build the application and test the application and then only we can deploy the code in production server.

To overcome this problem we can specify all reusable elements in the web.config file using OutputCache.

Specify cache settings in web.config using cache profiles.

<system.web>
  <caching>
    <outputCacheSettings>
      <outputCacheProfiles>
        <clear/>
        <add name="1MinuteCache" duration="60" varyByParam="none"/>            
      </outputCacheProfiles>
    </outputCacheSettings>
  </caching>
</system.web>

Change the application code

[OutputCache(CacheProfile = "1MinuteCache")]
public ActionResult Index()
{
    return View(db.Employees.ToList());
}

Now as OutputCacheProfile is set in web.config file so we no need to touch the source code and neither application needs any build to reflect the changes.

No comments:

Post a Comment