NET Caching Library Help
Primary Property
Example 




KellermanSoftware.NetCachingLibrary Namespace > SmartCache Class : Primary Property
The primary cache for storage, normally a memory cache
Syntax
'Declaration
 
Public ReadOnly Property Primary As BaseCacheProvider
'Usage
 
Dim instance As SmartCache
Dim value As BaseCacheProvider
 
value = instance.Primary
public BaseCacheProvider Primary {get;}
public: __property BaseCacheProvider* get_Primary();
public:
property BaseCacheProvider^ Primary {
   BaseCacheProvider^ get();
}
Example
//Create a Primary Cache with no backing cache
SmartConfig config = new SmartConfig(new MemoryCacheProvider());
            
//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
//The get cache key method uses reflection to ensure uniqueness
string cacheKey = cache.BuildCacheKey("MonthlySalesReport", month, year);
            
//Attempt to load the report from the cache
List<ReportDetail> report = cache.Get<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 of 20 minutes for the memory cache
	cache.Set<List<ReportDetail>>(cacheKey, report);
}
'Create a Primary Cache with no backing cache
Dim config As New SmartConfig(New MemoryCacheProvider())
            
'Specify UserName and LicenseKey for Licensed Mode
'config.UserName = "my user name";
'config.LicenseKey = "my license key";
            
'Instantiate the cache
Dim cache As New SmartCache(config)
            
'Build parameters for the report
Dim month As Integer = Date.Now.Month
Dim year As Integer = Date.Now.Year
            
'Get the cache key based on the report parameters
'The get cache key method uses reflection to ensure uniqueness
Dim cacheKey As String = cache.BuildCacheKey("MonthlySalesReport", month, year)
            
'Attempt to load the report from the cache
Dim report As List(Of ReportDetail) = cache.Get(Of List(Of ReportDetail))(cacheKey)
            
'Not found in the cache
If report Is Nothing Then
	'Load the report from the database
	report = ReportLogic.MonthlySalesReport(month, year)
            
	'Save to the cache using the default expiration of 20 minutes for the memory cache
	cache.Set(Of List(Of ReportDetail))(cacheKey, report)
End If
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

SmartCache Class
SmartCache Members