PomeloFoundation/Caching-MySQL

SetAsync ignoring DefaultSlidingExpiration set in MySqlCacheOptions

Closed this issue · 2 comments

using Pomelo.Extensions.Caching.MySql version 2.1.3

DI:

services.AddDistributedMySqlCache(opts =>
            {
                opts.ConnectionString = config.GetConnectionString("DistributedCache");
                opts.SchemaName = "DistributedCache";
                opts.TableName = "ApiCache";
                opts.DefaultSlidingExpiration = TimeSpan.FromMinutes(10);
            });

Usage:

_cache.Set(  "my_key", Encoding.UTF8.GetBytes("my_value") );

Error:

System.InvalidOperationException: Either absolute or sliding expiration needs to be provided.
   at Pomelo.Extensions.Caching.MySql.DatabaseOperations.ValidateOptions(Nullable`1 slidingExpiration, Nullable`1 absoluteExpiration)
   at Pomelo.Extensions.Caching.MySql.DatabaseOperations.SetCacheItem(String key, Byte[] value, DistributedCacheEntryOptions options)
   at Pomelo.Extensions.Caching.MySql.MySqlCache.Set(String key, Byte[] value, DistributedCacheEntryOptions options)
   at Microsoft.Extensions.Caching.Distributed.DistributedCacheExtensions.Set(IDistributedCache cache, String key, Byte[] value)

Expectation: If DistributedCacheEntryOptions.SlidingExpiration is not specified, the Set should use the DefaultSlidingExpiration as set in the AddDistributedMySqlCache options.