You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.SqlServer;
.
.
.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IDistributedCache>(serviceProvider =>
new SqlServerCache(
new CacheOptions( new SqlServerCacheOptions()
{
ConnectionString = @"Data Source=localhost;Initial Catalog=CacheDB;Integrated Security=False;User Id=sa;Password=pippo",
SchemaName = "dbo",
TableName = "testCache"
})
));
}
public void Configure(IApplicationBuilder app, IDistributedCache cache)
{
var serverStartTimeString = DateTime.Now.ToString();
byte[] val = Encoding.UTF8.GetBytes(serverStartTimeString);
cache.Set("lastServerStartTime", val);
app.Run(async (context) =>
{
context.Response.ContentType = "text/html";
await context.Response.WriteAsync("Hello World!");
});
}
but when I execute the code, I receive the error "Either absolute or sliding expiration needs to be provided.".
This because at line 33 of Microsoft.Extensions.Caching.Abstractions/DistributedCacheExtensions.cs the DistributedCacheEntryOptions parameter is a new value, with no setting for AbsoluteExpirationRelativeToNow or SlidingExpiration property.
If i use
cache.Set("lastServerStartTime", val, new DistributedCacheEntryOptions()
{
AbsoluteExpirationRelativeToNow = new TimeSpan(1,0,0)
});
All works fine.
Need to modify Microsoft.Extensions.Caching.Abstractions/DistributedCacheExtensions.cs to pass default value forAbsoluteExpirationRelativeToNow or SlidingExpiration ??