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




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

Parameters

key
The unique identifier for the cache item.
serviceFunction
The function to call if is not found in the cache.
serviceParms
The parameters to pass to the service function.
regionName
Optional. Name of the region. The default value is Default

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> parms = new Dictionary<string, object>();
parms.Add("Month", DateTime.Now.Month);
parms.Add("Year", DateTime.Now.Year);
            
//Get the cache key based on the report parameters
string cacheKey = cache.BuildCacheKey("MonthlySalesReport", parms);
            
//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>>(cacheKey, ReportLogic.MonthlySalesReport, parms);
'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 parms As New Dictionary(Of String, Object)()
parms.Add("Month", Date.Now.Month)
parms.Add("Year", Date.Now.Year)
            
'Get the cache key based on the report parameters
Dim cacheKey As String = cache.BuildCacheKey("MonthlySalesReport", parms)
            
'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))(cacheKey, ReportLogic.MonthlySalesReport, parms)
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