Open sandboxFocus

Class RedisCacheDependencyGarbageCollector

Removes dependencies added by a RedisCachingBackend when items are expired or evicted from the cache. At least one instance (ideally a single instance) of the RedisCacheDependencyGarbageCollector must be running whenever a RedisCachingBackend instance that supports dependencies is running, otherwise the cache will use storage to store dependencies that are no longer relevant, and these dependencies will not be removed. If no RedisCacheDependencyGarbageCollector is running while at least one dependency-enabled RedisCachingBackend instance is running, you must initiate a full garbage collection by calling the PerformFullCollectionAsync(RedisCachingBackend, CancellationToken) method.

Inheritance
RedisCacheDependencyGarbageCollector
Implements
Namespace: PostSharp.Patterns.Caching.Backends.Redis
Assembly: PostSharp.Patterns.Caching.Backends.Redis.dll
Syntax
public sealed class RedisCacheDependencyGarbageCollector : IDisposable
Remarks

The collector must use the same KeyPrefix and Database as the application, and its configuration must have SupportsEvents set to true. It can run in a separate process or service.

The collector performs two tasks. It subscribes to the expired and evicted keyevent notifications of Redis and removes the dependencies of the removed items. The Redis server must therefore publish these notifications (notify-keyspace-events Exe). The collector also periodically scans the database and removes unreachable data, according to RedisCacheDependencyGarbageCollectorOptions. The real-time processing stops while the background task queue is overloaded (see BackgroundTasksOverloadedThreshold).

Several instances can run at the same time, but they process the same notifications, so a single instance is preferable. To start a cleanup manually, call CleanUpAsync(CacheCleanupOptions, CancellationToken).

Properties

Name Description
Connection

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

Database

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

Options

Gets the options for the RedisCacheDependencyGarbageCollector.

Methods

Name Description
Create(CachingBackend, RedisCacheDependencyGarbageCollectorOptions)

Creates a new RedisCacheDependencyGarbageCollector that uses an existing PostSharp.Patterns.Caching.Backends.Redis.DependenciesRedisCachingBackend object.

Create(IConnectionMultiplexer, RedisCachingBackendConfiguration, RedisCacheDependencyGarbageCollectorOptions)

Creates a new RedisCacheDependencyGarbageCollector given a Redis connection and a configuration object.

CreateAsync(CachingBackend, RedisCacheDependencyGarbageCollectorOptions, CancellationToken)

Asynchronously creates a new RedisCacheDependencyGarbageCollector that uses an existing RedisCachingBackend object.

CreateAsync(IConnectionMultiplexer, RedisCachingBackendConfiguration, RedisCacheDependencyGarbageCollectorOptions, CancellationToken)

Asynchronously creates a new RedisCacheDependencyGarbageCollector given a Redis connection and a configuration object.

Dispose()

Disposes the current object.

DisposeAsync(CancellationToken)

Asynchronously disposes the current object.

PerformFullCollectionAsync(RedisCachingBackend, CancellationToken)

Performs a full garbage collection on all Redis servers. This operation enumerates and validates all keys in the database, and can possibly last several minutes and affect performance in production.

WhenBackgroundTasksCompleted(CancellationToken)

Awaits until all background tasks have completed.

See Also