views:

193

answers:

0

When using the @OutputCache directive, you can define cache profiles as follows in web.config:

<system.web>
  <caching>
    <outputCacheSettings>
      <outputCacheProfiles>
        <add name="myprofile" duration="30" enabled="true" varyByParam="myfield"/>
      </outputCacheProfiles>
    </outputCacheSettings>
  </caching>
</system.web>

However, in my app, I have some pages that need to use programmatic caching instead of declarative e.g.:

Response.Cache.SetExpires(DateTime.Now.AddSeconds(5));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

Is it possible to use Response.Cache and leverage the outputCacheProfiles? For example,

Response.Cache.ApplyCacheProfile("myprofile");