For easy access, baby
I just made my first (perhaps long over due) contribution to open source. I created a project on Codeplex called EasyCache.NET. I wasn’t quite sure what I was doing when I created the project, so I can’t be sure I followed the proper open source etiquette, nevertheless its now available.
EasyCache.NET is a project with the rather modest goal of slightly improving the manner in which developers can interact with the ASP.NET Cache object. It grew out of some similar code I had written to simplify a lot of repetitive boilerplate caching code sprinkled around our codebase. I realized afterwards that it wouldn’t take much effort to genericize it a bit further for general consumption.
The best way to explain what its all about is with the following typical sample, and show how EasyCache simplifies it.
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;
}
And now the EasyCache way:
public DataTable GetCustomers()
{
string cacheKey = "CustomersDataTable";
return Cache.Get(cacheKey,GetCustomersFromDataSource);
}
Checkout it and let me know what you think.
Comments
Post a Comment