Skip to content

Caching

Tanveer Yousuf edited this page Aug 9, 2018 · 2 revisions

Caching Overview

You can add an object of any type to cache along with a unique key. A key can be any arbitary string as long as its unique in the cache for a given object. Once you add an object to cache, you can retrieve it anytime after that.

In DevAccelerate Core, you create an instance of the IDaCacheManager type by calling the CreateCacheManager method of the DaApplicationContext class. Once you have a cache manager object, you can call its members to work with the underlying caching framework.

Create a Cache Manager

Before you can do any caching operations such as adding and retrieving objects from cache, you need to create a cache manager:

var cacheManager = DaCacheManagerFactory.CreateCacheManager();

Add an Object to Cache

You call the Add method to add an object to the cache:

var employee = new Employee();
cacheManager.Add("employee_" + employee.Id, employee);

Retrieve an Object from Cache

You can call the GetData method to retrieve an object from cache:

var employee = cacheManager.GetData("employee_" + employeeId));

Check if a Key Exists in Cache

You can call the Contains method to check if a key exists in cache:

if(cacheManager.Contains("employee_" + employeeId))
{
    // Do something
}

Clear Cache

You can call the Flush method to clear cache:

cacheManager.Flush();
Clone this wiki locally