views:

349

answers:

3

I'm building a caching system and I want it to be ready for distributed caching a la memcached. What I'm looking to do is to convert a traditional Hashtable/Dictionary of (string -> object) and to allow per-item expiration to be handled by the Cache itself, in the way that the System.Web.Caching.Cache can do.

I'm aware that memcache requires some changes to your thinking about caching, especially with respect to managing expiration, but I don't have much experience with it yet. Does anyone know of an article/site/etc with a cache wrapper around a distributed cache? I'd like to try to understand how it's possible to control cache size, prioritize items in the cache based on how much they're used, etc.

Thanks! Steve

PS - I haven't seen enough yet about Velocity to know whether the same hash-key model applies, if you know much about Velocity I'd appreciate any help as well!

+1  A: 

You could check out one of the open source Memcached wrappers for .Net. That might be helpful. Here's one from Sourceforge I was running in production for a while.

Memcached .net

Tim Merrifield
A: 

This might be helpful Memcached Providers

Fahad
+1  A: 

The most important thing is to make sure that your application is easy to port, follow normal DI/IOC (Dependency injection/Inversion of control) principles. So code that depends on the cache should not

  • Get a reference to the cache themself
  • Reference a Dictionary<,> object

Instead, make sure that the code

  • Call the cache through an interface, eg IDictionary<,>
  • Get the reference to the cache injected

If you are using a DI framework, then when you make the move to memcached, you just change the DI configuration code, and all your components that need the cache will now work with memcached.

And if you found out that one particular memcached .NET component doesn't work well, you can change it easily.

Pete