Open sandboxFocus

Class RedisCacheDependencyGarbageCollector

A background service that cleans up orphaned dependency keys in a Redis-based caching backend. This garbage collector runs periodically to detect and remove keys that are no longer valid, such as forward and backward dependency keys whose associated value keys have expired or been evicted.

Inheritance
RedisCacheDependencyGarbageCollector
Namespace: Metalama.Patterns.Caching.Backends.Redis
Assembly: Metalama.Patterns.Caching.Backends.Redis.dll
Syntax
public sealed class RedisCacheDependencyGarbageCollector : IRedisCacheDependencyGarbageCollector, IHostedService, IAsyncDisposable, IDisposable
Remarks

The garbage collector operates by subscribing to Redis keyevent notifications for expired and evicted keys, and by periodically running a full cleanup scan. When a value key is evicted or expires, the collector removes the associated version, forward dependency, and backward dependency keys.

This class implements IHostedService and can be registered as a hosted service in ASP.NET Core applications, or manually initialized using Initialize() or InitializeAsync(CancellationToken).

Properties

Name Description
Database

Gets the Redis StackExchange.Redis.IDatabase used by the current object.

Options

Gets the options for the RedisCacheDependencyGarbageCollector.

Methods

Name Description
Dispose()

Disposes the current object.

DisposeAsync()

Asynchronously disposes the current object using the default cancellation token.

DisposeAsync(CancellationToken)

Asynchronously disposes the current object.

Initialize()

Initializes the garbage collector synchronously. This method must be called before the garbage collector can process eviction notifications or perform cleanup operations.

InitializeAsync(CancellationToken)

Initializes the garbage collector asynchronously. This method must be called before the garbage collector can process eviction notifications or perform cleanup operations.

PerformFullCollectionAsync(CancellationToken)

Performs a full garbage collection scan of all Redis keys. This method initializes the backend if necessary and then scans all keys to detect and fix orphaned dependency entries.

ToString()
WhenBackgroundTasksCompleted(CancellationToken)

Awaits until all background tasks have completed.

Extension Methods