Applying OutputCache in a REST service
In WCF REST service development, we will often encounter some cases in which we will return certain data that is very expensive to generate or is not frequently changed. For such REST service operations, WCF 4.0 adopts the OutputCache
feature in ASP.NET web application platform so that the response of WCF REST service operations can also be cached at the server side according to some user-defined cache profile settings.
In this recipe, we will show you how to use the OutputCache
feature in a WCF REST service.
How to do it...
The following steps will guide you in how to apply a simple OutputCache
profile (which makes the operation response be cached for 30 seconds) onto a sample REST service:
Define an
OutputCache
profile.The REST service in WCF 4.0 directly takes advantage of the
OutputCache
functionality of ASP.NET runtime. So, we need to define a cache profile through the ASP.NET<outputCacheSettings>
configuration entries. The following configuration...