//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);
//Turn on throwing exceptions (the default is true)
cache.ThrowExceptions = true;
//Log to Console
cache.EnableLogging();
//Log to a File
string fileLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests", "log.txt");
cache.EnableLogging(fileLogPath);
//Log to memory
MemoryStream memoryStream = new MemoryStream();
cache.EnableLogging(ref memoryStream);
//Save it as a string
cache.Set<string>("Key", "This is a test");
//Loading it as an integer will throw an exception
try
{
var result = cache.Get<int>("Key");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}