NET Caching Library Help
Get<T>(SmartParms,Func<Dictionary<String,Object>,T>,Dictionary<String,Object>) Method
Example 




KellermanSoftware.NetCachingLibrary Namespace > SmartCache Class > Get Method : Get<T>(SmartParms,Func<Dictionary<String,Object>,T>,Dictionary<String,Object>) Method
Parameters specifying the key, region, and expiration
The function to call if is not found in the cache.
The parameters to pass to the service function.
Gets the specified item in the cache or insert the item using the result of the service function
Syntax
'Declaration
 
Public Overloads Function Get(Of T)( _
   ByVal parms As SmartParms, _
   ByVal serviceFunction As System.Func(Of Dictionary(Of String,Object),T), _
   ByVal serviceParms As System.Collections.Generic.Dictionary(Of String,Object) _
) As T
'Usage
 
Dim instance As SmartCache
Dim parms As SmartParms
Dim serviceFunction As System.Func(Of Dictionary(Of String,Object),T)
Dim serviceParms As System.Collections.Generic.Dictionary(Of String,Object)
Dim value As T
 
value = instance.Get(Of T)(parms, serviceFunction, serviceParms)
public T Get<T>( 
   SmartParms parms,
   System.Func<Dictionary<string,object>,T> serviceFunction,
   System.Collections.Generic.Dictionary<string,object> serviceParms
)
public: T* Get<T>( 
   SmartParms* parms,
   System.Func<Dictionary<string*,Object*>*,T*>* serviceFunction,
   System.Collections.Generic.Dictionary<string*,Object*>* serviceParms
) 
public:
T^ Getgeneric<typename T>
( 
   SmartParms^ parms,
   System.Func<Dictionary<String^,Object^>^,T^>^ serviceFunction,
   System.Collections.Generic.Dictionary<String^,Object^>^ serviceParms
) 

Parameters

parms
Parameters specifying the key, region, and expiration
serviceFunction
The function to call if is not found in the cache.
serviceParms
The parameters to pass to the service function.

Type Parameters

T

Return Value

T.
Example
//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
Dictionary<string, object> reportParms = new Dictionary<string, object>();
reportParms.Add("Month", DateTime.Now.Month);
reportParms.Add("Year", DateTime.Now.Year);
            
//Get the cache key based on the report parameters
string cacheKey = cache.BuildCacheKey("MonthlySalesReport", reportParms);
            
SmartParms smartParms = new SmartParms(cacheKey, "Default",
	DateTimeOffset.Now.AddMinutes(20), //Expire after 20 minutes in memory
	cache.GetEndOfDay()); //Expire at the end of the day for the file cache
            
//Get the report from the cache, if it does not exist, call the ReportLogic.MonthlySalesReport, save it to the cache and return it
List<ReportDetail> result = cache.Get<List<ReportDetail>>(smartParms, ReportLogic.MonthlySalesReport, reportParms);
'Create a Primary Memory Cache with a backing File Cache
Dim directory As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests")
Dim config As 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
Dim cache As New SmartCache(config)
            
'Build parameters for the report
Dim reportParms As New Dictionary(Of String, Object)()
reportParms.Add("Month", Date.Now.Month)
reportParms.Add("Year", Date.Now.Year)
            
'Get the cache key based on the report parameters
Dim cacheKey As String = cache.BuildCacheKey("MonthlySalesReport", reportParms)
            
Dim smartParms As New SmartParms(cacheKey, "Default", DateTimeOffset.Now.AddMinutes(20), cache.GetEndOfDay()) 'Expire at the end of the day for the file cache - Expire after 20 minutes in memory
            
'Get the report from the cache, if it does not exist, call the ReportLogic.MonthlySalesReport, save it to the cache and return it
Dim result As List(Of ReportDetail) = cache.Get(Of List(Of ReportDetail))(smartParms, ReportLogic.MonthlySalesReport, reportParms)
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
Overload List