This library is in pre-pre-pre-release, and does not work because of an issue found on the base library that tries to cache a non-serializeble object.
I've already sent a pull request that fixes the problem, waiting to be merged/discussed.
Extension to Strathweb CacheOutput WebApi2 for Microsoft AppFabric Distributed Caching
You can build from the source here, or you can install the Nuget version:
For Web API 2 (.NET 4.5)
PM> Install-Package Strathweb.CacheOutput.WebApi2.AppFabric
You can register your implementation using a GlobalConfiguration static method:
// instance
GlobalConfiguration.Configuration.CacheOutputConfiguration().RegisterCacheOutputProvider(() => new AppFabricApiOutputCache());
// singleton
var cache = new AppFabricApiOutputCache();
GlobalConfiguration.Configuration.CacheOutputConfiguration().RegisterCacheOutputProvider(() => cache);
Or you can register your implementation using a handy HttpConfiguration extension method:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// instance
config.CacheOutputConfiguration().RegisterCacheOutputProvider(() => new AppFabricApiOutputCache());
// singleton
var cache = new AppFabricApiOutputCache();
config.CacheOutputConfiguration().RegisterCacheOutputProvider(() => cache);
}
}
If you prefer CacheOutput to use resolve the cache implementation directly from your dependency injection provider, that's also possible. Simply register your IApiOutputCache implementation in your Web API DI and that's it. Whenever CacheOutput does not find an implementation in the GlobalConiguration, it will fall back to the DI resolver. Example (using Autofac for Web API):
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
cache = new AppFabricApiOutputCache();
var builder = new ContainerBuilder();
builder.RegisterInstance(cache);
config.DependencyResolver = new AutofacWebApiDependencyResolver(builder.Build());
}
}
If no implementation is available in neither GlobalConfiguration or DependencyResolver, we will default to System.Runtime.Caching.MemoryCache.