You can define a VistaDb secondary cache provider by specifying the CachePath or the connection string. If the CachePath is specified, the database will be automatically created if it does not exist. The tables and stored procedures will be automatically created in the database when the Setup command is executed or when the first item is loaded or saved to the cache. Your version of VistaDB must be 3.0 or higher to use stored procedures or an exception will occur.
//** Example setup of VistaDB Provider
VistaDbCacheProvider vistaProvider =
new
VistaDbCacheProvider();
vistaProvider.CachePath =
@"c:\Cache.vdb3"
;
vistaProvider.MaxCacheItems = 1000;
vistaProvider.MaxMegabytes = 100;
vistaProvider.Encrypt = true;
vistaProvider.EncryptionKey =
"secret"
;
vistaProvider.UseStoredProcedures = true;
vistaProvider.Setup();
//Attach the VistaDB provider as the secondary storage
SmartCache.Storage = vistaProvider;
//** Example Load and Save
//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);
}