.NET Caching Library Usage

Example of loading a monthly sales report from the cache. It demonstrates attaching a file storage provider and loading and saving to the cache.
 

//Attach a file cache provider

SmartCache .Storage= new FileCacheProvider ();

  //Build parameters for the report
int month = DateTime .Now.Month;
int year = DateTime .Now.Year;
 
//Get the cache key based on the report parameters
//The get cache key method uses reflection to ensure uniqueness
string cacheKey = SmartCache .GetCacheKey(month, year);
 
  //Attempt to load the report from the cache
List < ReportDetail > report = SmartCache .Load< List < ReportDetail >>(cacheKey);
 
//Not found in the cache
if (report == null )
{
//Load the report from the database
report = ReportLogic .MonthlySalesReport(month, year);
//Save to the cache using the default expiration type and default expiration minutes
SmartCache .Save< List < ReportDetail >>(cacheKey, report);

}