{"record":{"id":"135d7292c4c2a03d","repo":"dotnet/aspnetcore","slug":"expireditemsdeletioninterval-cannot-be-less-than-t","errorCode":null,"errorMessage":"ExpiredItemsDeletionInterval cannot be less than the minimum value of {0} minutes.","messagePattern":"ExpiredItemsDeletionInterval cannot be less than the minimum value of (.+?) minutes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Caching/SqlServer/src/SqlServerCache.cs","lineNumber":47,"sourceCode":"    private readonly TimeSpan _defaultSlidingExpiration;\n    private readonly Object _mutex = new Object();\n\n    /// <summary>\n    /// Initializes a new instance of <see cref=\"SqlServerCache\"/>.\n    /// </summary>\n    /// <param name=\"options\">The configuration options.</param>\n    public SqlServerCache(IOptions<SqlServerCacheOptions> options)\n    {\n        var cacheOptions = options.Value;\n\n        ArgumentThrowHelper.ThrowIfNullOrEmpty(cacheOptions.ConnectionString);\n        ArgumentThrowHelper.ThrowIfNullOrEmpty(cacheOptions.SchemaName);\n        ArgumentThrowHelper.ThrowIfNullOrEmpty(cacheOptions.TableName);\n\n        if (cacheOptions.ExpiredItemsDeletionInterval.HasValue &&\n            cacheOptions.ExpiredItemsDeletionInterval.Value < MinimumExpiredItemsDeletionInterval)\n        {\n            throw new ArgumentException(\n                $\"{nameof(SqlServerCacheOptions.ExpiredItemsDeletionInterval)} cannot be less than the minimum \" +\n                $\"value of {MinimumExpiredItemsDeletionInterval.TotalMinutes} minutes.\");\n        }\n        if (cacheOptions.DefaultSlidingExpiration <= TimeSpan.Zero)\n        {\n#pragma warning disable CA2208 // Instantiate argument exceptions correctly\n            throw new ArgumentOutOfRangeException(\n                nameof(cacheOptions.DefaultSlidingExpiration),\n                cacheOptions.DefaultSlidingExpiration,\n                \"The sliding expiration value must be positive.\");\n#pragma warning restore CA2208 // Instantiate argument exceptions correctly\n        }\n\n        _systemClock = cacheOptions.SystemClock ?? new SystemClock();\n        _expiredItemsDeletionInterval =\n            cacheOptions.ExpiredItemsDeletionInterval ?? DefaultExpiredItemsDeletionInterval;\n        _deleteExpiredCachedItemsDelegate = DeleteExpiredCacheItems;\n        _defaultSlidingExpiration = cacheOptions.DefaultSlidingExpiration;","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Caching/SqlServer/src/SqlServerCache.cs#L29-L65","documentation":"Thrown by the SqlServerCache constructor (line 47) when SqlServerCacheOptions.ExpiredItemsDeletionInterval is set to a value less than the MinimumExpiredItemsDeletionInterval (5 minutes, line 21). The background expired-item scan runs at this interval; setting it too low would cause excessive database churn. The exception type is ArgumentException, thrown at construction time (typically during DI service registration), causing application startup failure.","triggerScenarios":"SqlServerCache is instantiated (via AddDistributedSqlServerCache or new SqlServerCache) with options.ExpiredItemsDeletionInterval set to a TimeSpan less than 5 minutes.","commonSituations":"Over-aggressive cleanup configuration; a misunderstanding that the value is in minutes vs seconds; copying a value from another cache provider without adjusting units; a config typo like TimeSpan.FromSeconds(30).","solutions":["Set ExpiredItemsDeletionInterval to at least 5 minutes, or leave it unset to use the default (30 minutes).","If faster cleanup is needed, leave it at the minimum and call DeleteExpiredCacheItems via a custom scheduled job.","Verify the configuration value is specified as a correct TimeSpan (e.g., \"00:30:00\" for 30 minutes in config)."],"exampleFix":"// before — below the 5-minute floor\nservices.AddDistributedSqlServerCache(o =>\n{\n    o.ExpiredItemsDeletionInterval = TimeSpan.FromSeconds(30);\n});\n\n// after — at or above the 5-minute minimum (or omit for default 30 min)\nservices.AddDistributedSqlServerCache(o =>\n{\n    o.ExpiredItemsDeletionInterval = TimeSpan.FromMinutes(5);\n});","handlingStrategy":"validation","validationCode":"// Validate before constructing\nvar minInterval = TimeSpan.FromMinutes(5);\nif (cacheOptions.ExpiredItemsDeletionInterval.HasValue\n    && cacheOptions.ExpiredItemsDeletionInterval.Value < minInterval)\n{\n    throw new ArgumentException($\"ExpiredItemsDeletionInterval must be >= {minInterval.TotalMinutes} minutes.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Leave ExpiredItemsDeletionInterval unset to use the safe 30-minute default.","If customizing, verify the value is >= 5 minutes."],"tags":["caching","sqlserver","distributed-cache","configuration","startup"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}