API reference — Caching

Nuvora.Nexus.Relay.Cache.InMemory

In-memory caching strategy for Nuvora Nexus Relay

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

Nuvora.Nexus.Relay.Cache.InMemory

InMemoryCachingStrategy

public sealed class InMemoryCachingStrategy : ICachingStrategy

ICachingStrategy backed by IMemoryCache. Suitable for single-instance caching; for a shared cache across instances use the Redis strategy.

Constructors

InMemoryCachingStrategy(IMemoryCache cache, IOptions<CachingOptions> 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.InMemory.DependencyInjection

InMemoryCacheServiceCollectionExtensions

public static class InMemoryCacheServiceCollectionExtensions

Registration helpers for the in-memory caching strategy.

Methods

static IServiceCollection AddRelayInMemoryCache(this IServiceCollection services, Action<CachingOptions>? configure = null)