GithubHelp home page GithubHelp logo

sleipner's Introduction

Sleipner

This is a caching, and general performance enhancement, library for the .NET Framework version 4 and above. Sleipner is also Odin's Eight Legged Horse.

My little Sleipner

About Sleipner

Sleipner is desgined to be an automatic wrapper around repositories and services to ensure high availablility and performance by backing the results of method invocations in memcached. There is also a Dictionary-backed CacheProvider available which can be used during development, or in environments that cannot use Memcached. However using Memcached is always recommended, as this ensures high availability.

Using Sleipner

By default Sleipner comes with an Enyim Memcached-based Memcached Provider (the EnyimMemcachedProvider-class). You can use the typical way of configuring EnyimMemcached:

<configSections>
  <sectionGroup name="enyim.com">
    <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
  </sectionGroup>
</configSections>
<enyim.com>
  <memcached protocol="Binary">
    <servers>
      <add address="localhost" port="11211" />
    </servers>
    <transcoder type="DR.Sleipner.EnyimMemcachedProvider.Transcoders.NewtonsoftTranscoder, DR.Sleipner.EnyimMemcachedProvider" factory="DR.Sleipner.EnyimMemcachedProvider.Transcoders.NewtonsoftProvider, DR.Sleipner.EnyimMemcachedProvider" />
  </memcached>
</enyim.com>

You then create a SleipnerProxy object that wraps around your Repository or Service class. Your Repo/Service must have an interface that specifies it's communication contract.

var myAwesomeProxy = new SleipnerProxy<IAwesomeService>(
    new AwesomeService(),
    new EnyimMemcachedProvider<IAwesomeService>(_memcachedClientInstance)
);

myAwesomeProxy.Config(a => {
    a.ForAll().CacheFor(120); //By default everything is cached in memcached for 2 minutes
    a.For(b => b.AwesomeMethod(Param.IsAny<string>(), Param.IsAny<int>()).CacheFor(10); //Any result from the AwesomeMethod is only cached for 10 seconds though
});

var myAwesomeService = myAwesomeProxy.Object; //the myAwesomeService object is now backed in memcached.

Need to know

Remember to adhere to the recommended usage pattern for MemcachedClient. It is a heavy object and should be kept in a static context. While the SleipnerProxy-class is not heavy to initialize, there is no reason not to keep it in a static context as well. Most IoC Frameworks (such as StructureMap and Ninject) supports doing this by configuration. Alternatively you can keep the instances as static members of your IOC Initialization class or in your Application-file (in web apps).

sleipner's People

Contributors

bobend avatar drtsvn avatar jalsdr avatar jonasswiatek avatar

Watchers

 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.