Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Extensions.Caching.PostgreSql/DatabaseExpiredItemsRemoverLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal sealed class DatabaseExpiredItemsRemoverLoop : IDatabaseExpiredItemsRem
private readonly IDatabaseOperations _databaseOperations;
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly ISystemClock _systemClock;
private readonly bool _disabled;

public DatabaseExpiredItemsRemoverLoop(
IOptions<PostgreSqlCacheOptions> options,
Expand All @@ -24,6 +25,12 @@ public DatabaseExpiredItemsRemoverLoop(
{
var cacheOptions = options.Value;

if ((_disabled = cacheOptions.Disabled) == true)
{
//No need to configure anything
return;
}

if (cacheOptions.ExpiredItemsDeletionInterval.HasValue &&
cacheOptions.ExpiredItemsDeletionInterval.Value < MinimumExpiredItemsDeletionInterval)
{
Expand All @@ -41,6 +48,11 @@ public DatabaseExpiredItemsRemoverLoop(

public void Start()
{
if (_disabled)
{
return;
}

Task.Run(DeleteExpiredCacheItems);
}

Expand Down
5 changes: 5 additions & 0 deletions Extensions.Caching.PostgreSql/PostGreSqlCacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class PostgreSqlCacheOptions : IOptions<PostgreSqlCacheOptions>
/// </summary>
public TimeSpan DefaultSlidingExpiration { get; set; } = TimeSpan.FromMinutes(20);

/// <summary>
/// If set to true this instance of the cache will not remove expired items.
/// </summary>
public bool Disabled { get; set; }

PostgreSqlCacheOptions IOptions<PostgreSqlCacheOptions>.Value => this;
}
}