VahidN / EFSecondLevelCache.Core

Entity Framework Core Second Level Caching Library
Apache License 2.0
326 stars 51 forks source link

Sliding expiration not work correctly #64

Closed ldias91 closed 4 years ago

ldias91 commented 4 years ago

Hi,

Environment

.NET Core SDK version:  3.1.100
Microsoft.EntityFrameworkCore version: 3.1.0
EFSecondLevelCache.Core version: 2.9.0

I set the global settings with absolute expiration:

services.AddSingleton(typeof(ICacheManagerConfiguration),
                new CacheManager.Core.ConfigurationBuilder()
                    .WithJsonSerializer(serializationSettings: jss, deserializationSettings: jss)
                    .WithUpdateMode(CacheUpdateMode.Up)
                    .WithRedisConfiguration(redisConfigurationKey, config =>
                    {
                        config.WithAllowAdmin()
                            .WithDatabase(0)
                            .WithEndpoint(Configuration["redis:connectionString"], 6379);
                    })
                    .WithMaxRetries(100)
                    .WithRetryTimeout(50)
                    .WithRedisCacheHandle(redisConfigurationKey)
                    .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMinutes(10))
                    .Build());

In query i change the expiration mode to sliding and timeout to 5 minutes

_contex.Users.AsNoTracking()
            .Cacheable(new EFCachePolicy(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(5)))

After 10 minutes, the user key is removed from the cache, so when I call the invalidate method, the key for the User entity no longer exists. Then you won't be able to remove the values from this key.

The value is only removed from the cache after 5 minutes without any queries executed. Until then will return inconsistent data.

Thanks

VahidN commented 4 years ago

It's fixed via #https://github.com/VahidN/EFSecondLevelCache.Core/commit/4d065dd44e060cfd0b1b84b147131c9b31af5e6e