Skip to main content

Redis Cache Helper

The ADS.RedisCache.Helper library provides a Service for interacting with a Redis cache, enabling efficient data storage and retrieval with support for expiration policies.

Summary

The ADS.RedisCache.Helper Library provides a structured way to interact with Redis for caching data efficiently. The IRedisCache Service ensures flexibility and reusability, enabling applications to enhance performance by reducing database calls and efficiently managing session persistence.

Service: IRedisCache

The RedisCache service defines essential methods for managing cached data within a Redis instance.

1. GetCacheData​

Description

Retrieves data from the Redis cache.

Parameters

  • key (string): The key associated with the cached data.

Returns

Task<T>: A task that returns the cached data of type T.

Example Usage

var cachedValue = await redisCache.GetCacheData\<string\>("user:123");

2. SetCacheData​

Description

Stores data in the Redis cache with an expiration time.

Parameters

  • key (string): The key associated with the data.
  • value (T): The data to be stored.
  • expirationMinutes (double): The time (in minutes) until the data expires.

Returns

Task: An asynchronous operation.

Example Usage

await redisCache.SetCacheData("user:123", userData, 60);

3. RemoveData​

Description

Removes data from the Redis cache.

Parameters

  • key (string): The key associated with the data to be removed.

Returns

Task: An asynchronous operation.

Example Usage

await redisCache.RemoveData("user:123");

4. RefreshData​

Description

Refreshes the expiration time of existing data in the Redis cache.

Parameters

  • key (string): The key associated with the data to refresh.

Returns

Task: An asynchronous operation.

Example Usage

await redisCache.RefreshData("user:123");