Sana Assistant (online)
Table of Contents

Extension.Api.Cache reference

This article provides reference material about cache API. Every extension has Api property which contains Cache property which provides the way to store any arbitrary data with configurable period of time and possibility to access this data later in subsequent requests.

The Cache property holds an instance of CacheManager type.

Methods

Class diagram

TryGetValue(CacheKey, out T)

Gets the item associated with this key and returns value indicating whether it is present in the cache storage.

Api.Cache.TryGetValue<string>(CacheKey.Create("product-key"), out var value);

Set(CacheKey, T, CacheOptions)

Remembers the value and stores it in cache for specified amount of time. The data will then be available during subsequent requests until specified expiration time ends.

Api.Cache.Set(CacheKey.Create("product-key"), "123", new CacheOptions());

Remove

Removes cache entry by cache key.

Api.Cache.Remove(CacheKey.Create("product-key"));

ClearAll

Removes all entries from the cache storage.

Api.Cache.ClearAll();

ClearGroup

Removes cache entries by group name.

Api.Cache.ClearGroup("group-key");

See also