.netasp.netcachingncache

Cache frameworks for .NET


I'm planning to develop a web service, i need to use in memory cache, what different caching frameworks are available out there for .NET, i have used Microsoft Enterprise Library Cache block and also evaluated NCache for distributed environment.

My core requirement is reliability with Cached data, i was thinking of using Enterprise Lib Cache block DB data store for persistence in case worker process get restarted.

Any options??


Solution

  • Your cache is a volatile data store, you should write your software so that it EXPECTS that the cache is unavailable. e.g.

    public DtoThing GetSomeData(string parameters)
    {
       if (<check cache for data> == <not there>)
         return <get data from persistent store>
       else
         return <get data from cache>
    }
    

    If you use a database as a backing store for the cache, you've basically just traded away all the benefits of using a cache. When you say the cache needs to be reliable, are you saying that the updates need to be consistent or that the data needs to always be in the cache? If the former, it's easy to make sure that happens as long as you write your software in such a way that there is only ever one path to update the data, and then that path can invalidate the cache upon successfully performing its write to the persistent data store.