Giter Club home page Giter Club logo

strathweb.cacheoutput.webapi2.appfabric's Introduction

Build status

DO NOT USE THIS LIBRARY!

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.

AppFabric implementation of ASP.NET Web API CacheOutput

Extension to Strathweb CacheOutput WebApi2 for Microsoft AppFabric Distributed Caching

Installation

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

Usage

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.

strathweb.cacheoutput.webapi2.appfabric's People

Contributors

micdenny avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.