EasyCache .NET simplified API

The sole purpose of this project it to provide a more concise syntax for adding and removing items from the ASP.NET cache. Caching data with the existing HttpRuntime.Cache object involves the repetitive use of boiler plate code, similiar to the following example from MSDN.


public DataTable GetCustomers()
{
string cacheKey = "CustomersDataTable";
object cacheItem = Cache[cacheKey] as DataTable;
if(cacheItem == null)
{
cacheItem = GetCustomersFromDataSource();
Cache.Insert(cacheKey, cacheItem, null,
DateTime.Now.AddSeconds(GetCacheSecondsFromConfig(cacheKey),
TimeSpan.Zero);
}
return (DataTable)cacheItem;
}

With EasyCache the same code can be written as:


public DataTable GetCustomers()
{
string cacheKey = "CustomersDataTable";
return Cache.Get(cacheKey,GetCustomersFromDataSource);
}


The latest version also includes:
A simple provider model. By implementing the ICacheProvider interface you'll be able to swap Cache implementations via configuration. I've provided two implementations; the MemoryCache which uses the standard .NET memory cache, and the SerializedMemoryCache which also uses that standard .NET memory cache but serializes objects in and out of the cache to simulate a distributed cache.

Last edited Jun 4, 2011 at 11:27 AM by jnappi, version 3