//Create a Primary Memory Cache with a backing File Cache
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests");
SmartConfig config = new SmartConfig(new MemoryCacheProvider(), new FileCacheProvider(directory));
//Specify UserName and LicenseKey for Licensed Mode
//config.UserName = "my user name";
//config.LicenseKey = "my license key";
//Instantiate the cache
SmartCache cache = new SmartCache(config);
//Build parameters for the report
int month = DateTime.Now.Month;
int year = DateTime.Now.Year;
//Get the cache key based on the report parameters
string cacheKey = cache.BuildCacheKey("MonthlySalesReport", month, year);
//Attempt to load the report from the cache
CacheItem cacheItem = cache.GetCacheItem<List<ReportDetail>>(cacheKey);
//Not found in the cache
if (cacheItem == null)
{
//Load the report from the database
List<ReportDetail> report = ReportLogic.MonthlySalesReport(month, year);
//Save to the cache using expiring 30 minutes from now for both the memory cache and the file cache
bool result = cache.Add<List<ReportDetail>>(cacheKey, report, DateTimeOffset.Now.AddMinutes(30), "Default");
//This will be true since it was added to the cache
Console.WriteLine(result);
}