ICacheApi Interface

Provide methods for caching.

Definition

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

Example

C#
                    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));
}
                  

Methods

ContainsKey Determines whether a cache entry exists in the cache.
GetT Returns an entry from the cache.
Remove Removes the specified item from the cache.
SetT(String, T) Inserts a cache entry into the cache by using a key and a value with default expiration time which is 15 minutes.
SetT(String, T, TimeSpan) Inserts a cache entry into the cache by using a key and a value and specifies time-based expiration details.
SetT(String, T, TimeSpan, Boolean) Inserts a cache entry into the cache by using a key and a value and specifies whether it is for sliding expiration or time-based expiration.
TryGetT Get item from cached if return true, otherwise it returns false

See Also