The ICacheService interface defines a standard set of operations for caching mechanisms. It provides methods for asynchronous and synchronous retrieval and storage of cache items, allowing for both timespan-based and datetime-offset-based expiration.
Additionally, it offers a mechanism to verify the existence of a specific cache key. Implement this interface to create consistent caching providers for different storage backends.
/// <summary>/// Common cache provider interface/// </summary>publicinterfaceICacheService{ /// <summary> /// Gets cache value /// </summary> /// <typeparamname="T">The type of result object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <returns>Object</returns>TGet<T>(string cacheKey); /// <summary> /// Gets cache value asynchronous /// </summary> /// <typeparamname="T">The type of result object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <returns>Object</returns>Task<T> GetAsync<T>(string cacheKey); /// <summary> /// Sets cache value asynchronous /// </summary> /// <typeparamname="T">The type of source object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <paramname="value">Object value</param> /// <paramname="expiresIn">Expires after given value</param>voidSet<T>(string cacheKey,T value,TimeSpan? expiresIn =null); /// <summary> /// Sets cache value asynchronous /// </summary> /// <typeparamname="T">The type of source object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <paramname="value">Object value</param> /// <paramname="expiresIn">Expires after given value</param>TaskSetAsync<T>(string cacheKey,T value,TimeSpan? expiresIn =null); /// <summary> /// Sets cache value synchronous /// </summary> /// <typeparamname="T">The type of source object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <paramname="value">Object value</param> /// <paramname="expiresOn">Expires on given date time offset</param>voidSet<T>(string cacheKey,T value,DateTimeOffset expiresOn); /// <summary> /// Sets cache value asynchronous /// </summary> /// <typeparamname="T">The type of source object</typeparam> /// <paramname="cacheKey">Cache key</param> /// <paramname="value">Object value</param> /// <paramname="expiresOn">Expires on given date time offset</param>TaskSetAsync<T>(string cacheKey,T value,DateTimeOffset expiresOn); /// <summary> /// Removes cache key /// </summary> /// <paramname="cacheKey">Cache key</param>voidDelete(string cacheKey); /// <summary> /// Removes cache key /// </summary> /// <paramname="cacheKey">Cache key</param>TaskDeleteAsync(string cacheKey); /// <summary> /// Checks given key is exist in cache or not /// </summary> /// <paramname="cacheKey">Cache key</param> /// <returns>true/false</returns>boolIsExists(string cacheKey);}