Wednesday, February 25, 2015

Caching with ASP.NET Web API

If you have recently started working with ASP.NET Web API, you may have noticed the lack of support for Caching.

There is currently no estimated timeframe as to when Microsoft will add support for Caching natively to ASP.NET Web API, but fortunately, there are 2 projects which add support for Caching to your existing ASP.NET Web API Projects!

  1. CacheCow: https://github.com/aliostad/CacheCow
  2. ASPNetWebAPI OutputCache: https://github.com/filipw/AspNetWebApi-OutputCache
 You can read more about the differences here: http://www.hanselman.com/blog/NuGetPackageOfTheWeekASPNETWebAPICachingWithCacheCowAndCacheOutput.aspx

Personally, amongst the 2 solutions, I prefer the ASPNetWebAPI OutputCache solution because it is more intuitive in using attribute based caching similar to how you can use this today in ASP.NET MVC.

 

1 comment:

  1. I prefer CacheCow as it can invalidate etags when there is put/patch/post/delete on the controller. So you won't have outdated data load from cache.

    ReplyDelete