MetalamaAPI documentationPatterns APIMetalama.​Patterns.​Caching.​Backends.​RedisRedis­Caching­FactoryAdd­Redis­Cache­Dependency­Garbage­Collector
Open sandboxFocus

RedisCachingFactory.AddRedisCacheDependencyGarbageCollector Method

AddRedisCacheDependencyGarbageCollector(IServiceCollection, RedisCachingBackendConfiguration)

Adds a service (implementing IHostedService) that removes dependencies added when a RedisCachingBackend when items are expired or evicted from the cache.

Declaration
public static IServiceCollection AddRedisCacheDependencyGarbageCollector(this IServiceCollection serviceCollection, RedisCachingBackendConfiguration configuration)
Parameters
Type Name Description
IServiceCollection serviceCollection
RedisCachingBackendConfiguration configuration
Returns
Type Description
IServiceCollection
Remarks

It is necessary to have at least one instance of the garbage collector active at any time, otherwise the cache will use storage to store dependencies that are no longer relevant, and will not be removed otherwise. It is allowed but redundant to have several concurrent instances of the garbage collector, but having a large number of them can hurt performance of the Redis server.

If no instance of this service is running during some time, you must initiate full garbage collection by calling the <see cref="RedisGarbageCollectionUtilities.PerformFullCollectionAsync(StackExchange.Redis.IConnectionMultiplexer,Metalama.Patterns.Caching.Backends.Redis.RedisCachingBackendConfiguration?,System.IServiceProvider?,System.Threading.CancellationToken)"/> method.

AddRedisCacheDependencyGarbageCollector(IServiceCollection, Func<IServiceProvider, RedisCachingBackendConfiguration>)

Declaration
public static IServiceCollection AddRedisCacheDependencyGarbageCollector(this IServiceCollection serviceCollection, Func<IServiceProvider, RedisCachingBackendConfiguration> configurationFactory)
Parameters
Type Name Description
IServiceCollection serviceCollection
Func<IServiceProvider, RedisCachingBackendConfiguration> configurationFactory
Returns
Type Description
IServiceCollection