dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.57k stars 25.3k forks source link

Overriding Expired items deletion operation in SQL server cache table - ExpiredItemsDeletionInterval #27212

Open HiremathVK opened 1 year ago

HiremathVK commented 1 year ago

Hi Team,

we are using SQL Server for distributed cache implementation using (Microsoft.Extensions.Caching.Distributed) "IDistributedCache" , the property "ExpiredItemsDeletionInterval" which trigger operation to delete all expired cache records in cache table creating lot of performance and deadlocks in DB server.

We are looking for the solution to disable this operation and have a simple DB job to delete cache records overnight everyday instead of deleting from application/API.

Issues with ExpiredItemsDeletionInterval property is set with default value to 30 min and no way to set it to null.

Implementation details: We have developed a Microservice which is hosted in Openshift container platform with Pod configuration min 24 to Max 32 as this API is used by all other microservices for caching. As ExpiredItemsDeletionInterval is not able to disable, each pod will trigger command to DB to delete all expired records and resulting in deadlock on cache table and DB will be killed hence due this all microservices will be impacted.

Is there a better way to override this ExpiredItemsDeletionInterval property so that deletion can be stopped ??

Thank you. Hiremath

Rick-Anderson commented 1 year ago

ExpiredItemsDeletionInterval = TimeSpan.FromDays(2);

What document is this related to?

HiremathVK commented 1 year ago

@Rick-Anderson : I don't want to set any time to delete expired cache records, looking for the solution to disable this operation, we have a separate DB Job to delete these expired records.

As i mentioned in problem statement, if I set ExpiredItemsDeletionInterval = sometime; then each and every Pod in Openshift container Platform trigger delete operation and ending db deadlock.

For more details, please refer below documents: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-6.0#distributed-sql-server-cache https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.sqlserver.sqlservercache?view=dotnet-plat-ext-3.1

https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.sqlserver.sqlservercacheoptions.expireditemsdeletioninterval?view=dotnet-plat-ext-3.1

Rick-Anderson commented 1 year ago

TimeSpan.FromDays(365 * 30);

Rick-Anderson commented 1 year ago

Issues with ExpiredItemsDeletionInterval property is set with default value to 30 min and no way to set it to null.

image

https://stackoverflow.com/a/62142926/502537