API reference — Caching

Nuvora.Nexus.Relay.Cache.Redis

Redis caching strategy for Nuvora Nexus Relay

dotnet add package Nuvora.Nexus.Relay.Cache.Redis

Nuvora.Nexus.Relay.Cache.Redis

RedisCacheOptions

public sealed class RedisCacheOptions

Options for the Redis caching strategy.

Properties

TimeSpan DefaultExpiration { get; set; }

Default expiration when a caller does not specify one.

string ConnectionString { get; set; }

StackExchange.Redis connection string (e.g. “localhost:6379”).

string? KeyPrefix { get; set; }

Optional key prefix to namespace entries per service/environment.

RedisCachingStrategy

public sealed class RedisCachingStrategy : ICachingStrategy

ICachingStrategy backed by Redis (StackExchange.Redis). Values are JSON-serialized. Safe to share across instances — combine with the deterministic CacheKeyGenerator so all instances compute identical keys.

StackExchange.Redis async APIs do not accept a CancellationToken; awaited calls here are wrapped in Task.WaitAsync so a caller’s token can abandon the wait. Note this only abandons the client-side await — the underlying Redis operation may still complete server-side.

Constructors

RedisCachingStrategy(IConnectionMultiplexer connection, IOptions<RedisCacheOptions> options)

Methods

Task RemoveAsync(string key, CancellationToken cancellationToken = default(CancellationToken))

Removes a value from cache

Task SetAsync<T>(string key, T value, TimeSpan expiration, CancellationToken cancellationToken = default(CancellationToken))

Sets a value in cache with expiration

Task<CacheResult<T>> TryGetAsync<T>(string key, CancellationToken cancellationToken = default(CancellationToken))

Gets a cached value with an explicit hit/miss outcome, so a cached null or default value-type payload is not mistaken for a miss.

Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default(CancellationToken))

Gets a cached value by key

Task<bool> ExistsAsync(string key, CancellationToken cancellationToken = default(CancellationToken))

Checks if a key exists in cache

Task<int> RemoveByPrefixAsync(string keyPrefix, CancellationToken cancellationToken = default(CancellationToken))

Removes every cached entry whose key starts with keyPrefix. Used to invalidate a logical group of entries (e.g. all cached results of one query type) without knowing each individual key. The prefix is matched against the same logical keys passed to ICachingStrategy.SetAsync/ICachingStrategy.RemoveAsync; implementations apply any storage-level namespace themselves.

Nuvora.Nexus.Relay.Cache.Redis.DependencyInjection

RedisCacheServiceCollectionExtensions

public static class RedisCacheServiceCollectionExtensions

Registration helpers for the Redis caching strategy.

Methods

static IServiceCollection AddRelayRedisCache(this IServiceCollection services, Action<RedisCacheOptions> configure)