Click or drag to resize

ICacheApi Interface

Provide methods for caching.

Namespace:  Casewhere.Runtime.DSL.Api
Assembly:  Casewhere.Runtime (in Casewhere.Runtime.dll) Version: 2.8.1.0
Syntax
C#
public interface ICacheApi

The ICacheApi type exposes the following members.

Methods
Examples
var dataApi = ctx.Use<IDataApi>(); 
var cacheApi = ctx.Use<ICacheApi>();

// In this example, we try to cache departments by id
var cacheKey = ctx.Input.DepartmentId;
object cached;

if (cacheApi.TryGet(cacheKey, out cached))
{
    Log.Info("Cached key {Key} found {Cached}.", cacheKey, cached);
}
else
{
    Log.Info("Cache key {Key} does not exist. Fetch from DB and cache...", cacheKey);
    var department = dataApi.Load(ctx.Input.DepartmentId);
    cacheApi.Set(cacheKey, department, TimeSpan.FromSeconds(120));
}
See Also