Using Sitecore 9.0.2, I've got code in two areas: SitecoreComponent (for controller renderings) and API (for JS calls). I've got a controller that inherits from SitecoreController in the API folder that I'm trying to apply the OutputCache attribute to, whether using a profile name or the parameters specifically in the attribute. This is also marked as HttpPost and called by an Ajax JQuery call to /api/[controller]/[method].
Whenever I make this call, either via the web application or Postman, I see in Fiddler or Postman that the cache-control is set to "no-cache". If I set up a VS debug against it, the method is hit, when it shouldn't need to be. So it appears the output caching is being bypassed/ignored.
Is this a scenario where the path needs to be added to the ignore path list, perhaps? If so, we'd probably need to institute a path other than "/api" since Sitecore can/does use that as well, I believe? Or is there something in Sitecore that overrides the OutputCache because it's taken over for use in the rendering caches and the like?
Code stub:
public class StockQuoteController : SitecoreController {
private IStockQuoteAgent _stockQuoteAgent;
public StockQuoteController(IStockQuoteAgent stockQuoteAgent) {
_stockQuoteAgent = stockQuoteAgent;
}
[OutputCache(CacheProfile = "StockQuoteCacheProfile")]
[HttpPost]
public JsonResult GetStockPrice() {
...
}
}
Cache definition (in web.config, inside system.web node):
<caching>
<outputCache enableOutputCache="true" enableFragmentCache="true" sendCacheControlHeader="true" omitVaryStar="false"></outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="StockQuoteCacheProfile" duration="1800" varyByParam="none" location="ServerAndClient" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>