What framework should I use to get a persistent cache?

I have some objects and classes that I'm currently saving into HttpContext.Cache but I want to make these persistent even when the app pool is recycled or even when the machine has been restarted. I tried looking into using AppFabric or Memcached but they seemed focused on distributed cache and not so much local cache. Also the EF STE in combination with AppFabric seem to be depending on serializable classes and some properties in my classes is for example references to .NET classes that is not serializable (For example I have a reference to an instance of System.Net.WebSockets.WebSocket as a property).

So my question is: Can anyone give me any good ideas or point me to a framework that will allow me to save classes into some sort of local cache that is persistent to disk (Or database if it will allow me to save anyhting into it)?

Upvotes: 3

Views: 1399

Answers (3)

Prathul
Prathul

Reputation: 88

The new Appfabric 1.1 has read-through and write-behind features which has guaranteed persistence of your cache.

Read through - If a requested item doesn't exist in the cache, the data can be loaded from backend store and then inserted into cache. With a read-through provider, the cache detects the missing item and calls the provider to perform the data load. The item is then seamlessly returned to the cache client.
Write behind - In the same way, items that are added or updated in the cache can be periodically written to the backend store using a write-through provider. This happens asynchronously and on an interval defined by the cache.

You can check out my blog post for implementation details here http://blogs.msdn.com/b/prathul/archive/2011/12/06/appfabric-cache-read-from-amp-write-to-database-read-through-write-behind.aspx

Upvotes: 1

Kassem
Kassem

Reputation: 8266

You should probably re-think the structure of your classes if you want them serialized. But as for the question at hand, if you want to cache objects and have them persisted across app pool recycling, then you should probably consider configuring HttpContext.Cache to use SQL Server instead of in-process memory. Check out the following links:

ASP.NET Caching Overview

Walkthrough: Using ASP.NET Output Caching with SQL Server

Note though that it is a good practice to use wrappers over any technology/platform specific resources. For instance, it's much better to use a CacheWrapper class which basically accesses HttpContext.Cache internally. This way, you can easily alter your implementation of the wrapper class to use another cache store in case you needed to.

Upvotes: 0

Simon Thompson
Simon Thompson

Reputation: 704

Look at RavenDB - its a NoSQL db but very lightweight and very intergrated with .net so you can just store your classes and get them back as instances of this class.

Upvotes: 0

Related Questions