The CacheHelper function helps you cache data for faster retrievals. The ICacheHelper instance, which is returned when GetCacheHelper() is called, provides you with the following methods:

Methods

void Set<T>(string key, T value, string regionName);
T Get<T>(string key, string regionName);
bool Contains(string key, string regionName);
CODE

Example

public class Product2
{
  public string Id {get; set;}
  public string Name { get; set;}
}
CODE

Set Data in Cache

var cacheHelper = GetCacheHelper();

Product2 product = new Product2()
{
  Id= "RT001", Name =  "Router"
};
await cacheHelper.Set<Product2>("Product",product);
CODE

Console Output

{"Id":"RT001","Name":"Router"}
CODE

Get Data from Cache

var cacheHelper = GetCacheHelper();
var logHelper = GetLogHelper();
		 
var productFromCache = await cacheHelper.Get<Product2>("Product");
logHelper.LogDebug(productFromCache);
CODE

Console Output

{"Id":"RT001","Name":"Router"}
CODE