CacheAdapterV2 Now with memcached support
Posted by: Glavs Blog,
on 04 Jul 2011 |
View original | Bookmarked: 0 time(s)
Previously I blogged about my CacheAdapter project that is available as a Nuget package and allows you to program against a single interface implementation, but have support for using Memory, ASP.NET Web or Windows AppFabric cache mechanisms via configuration.
I am happy to announce that my CacheAdapter now has support for memcached. Version 2 of the Nuget package is available here. Alternatively, all the source code is available here.
What this now means is you can write one line of code to get or store an item in the cache, and that code can automatically support using Windows AppFabric, memcached, MemoryCache or ASP.NET web cache. No code change required.
I am particularly happy about having memcached support as it means a few things:
- Free / Open Source: It is a free, well established open source caching engine that is widely used in many applications.
- Easy: It is easy to setup.
- Simple and Cheap: It provides an alternative to using Windows AppFabric. AppFabric can be a little tricky to setup sometimes. If you are using Windows Azure, AppFabric is a simple checkbox BUT you need to pay extra for the privilege of using it based on how much you use the cache service. By contrast, memcached can be installed easily on Azure and requires no extra cost whatsoever.
- Auto fail over support: In addition, Windows AppFabric has some limitations for a relatively small cache farm. AppFabric utilises a lead host to co-ordinate small cache farms of 3 or less cache servers. If the lead host goes down, they all go down. The memcached implementation has no reliance on any single point of failure so if one memcached node fails, requests will automatically be redirected to the nodes that are alive. If the dead node comes back alive again, it is re-introduced to the cache pool after about 1 minute or so. At worst, it results in a few cache misses.
Note: This release contains a few namespace changes that may break older versions if you are using the objects directly. Namely AppFabric object support has been moved from the Glav.CacheAdapter.Distributed namespace to the Glav.CacheAdapter.Distributed.AppFabric namespace. This is to allow differentiation from AppFabric and memcached within the distributed namespace.
In addition, at the request of some users, I have added a simple Add method to the ICacheProvider interface for ease of use. The interface now looks like this:
public interface ICacheProvider
T Get<T>(string cacheKey, DateTime absoluteExpiryDate, GetDataToCacheDelegate<T> getData, bool addToPerRequestCache = false) where T : class;
T Get<T>(string cacheKey, TimeSpan slidingExpiryWindow, GetDataToCacheDelegate<T> getData, bool addToPerRequestCache = false) where T : class;
void InvalidateCacheItem(string cacheKey);
void Add(string cacheKey, DateTime absoluteExpiryDate, object dataToAdd);
void Add(string cacheKey, TimeSpan slidingExpiryWindow, object dataToAdd);
void AddToPerRequestCache(string cacheKey, object dataToAdd);
So that is it. I hope you enjoy using memcached support within the CacheAdapter.