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 has been 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 ??
The text was updated successfully, but these errors were encountered:
@iscifoni Thanks for reporting this. This behavior is not ideal. For now you could probably create a new extension on IDistributedCache which sets these options.
Tratcher
changed the title
SQLCache set default value on DistributedCacheEntryOptions
SQLCache Set should allow a null timeout
Jun 28, 2016
I am thinking that SQL Server cache should have a default sliding expiration for a cache entry, let's say 20 mins, if none specified by a user. These default timeout options would be exposed by SqlServerCacheOptions.
I have implemented sql cache:
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
All works fine.
Need to modify Microsoft.Extensions.Caching.Abstractions/DistributedCacheExtensions.cs to pass default value forAbsoluteExpirationRelativeToNow or SlidingExpiration ??
The text was updated successfully, but these errors were encountered: