admin 管理员组文章数量: 1086019
I'm working on a POC for the HybridCache for one of our internal libraries and I want to allow consumers the ability to decide whether they want to enable or disable the local cache. I'm using Couchbase as the L2 cache and I have a pretty basic configuration
builder.Services.AddCouchbase(builder.Configuration.GetSection("Couchbase"));
builder.Services.AddDistributedCouchbaseCache(options =>
{
options.BucketName = "cachebucket";
});
builder.Services.AddHybridCache(options =>
{
options.DefaultEntryOptions = new HybridCacheEntryOptions
{
Flags = HybridCacheEntryFlags.DisableLocalCache
};
});
[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get()
{
return await _hybridCache.GetOrCreateAsync("weather-forecast", factory: async _ => await GetData());
}
private static async Task<WeatherForecast[]> GetData()
{
await Task.Delay(1000 * 5); // wait for for 5 seconds
var data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
return data;
}
When I call the GetOrCreateAsync() method, the initial call fetches the data from the factory as expected. The data is correctly populated to Couchbase as well
On subsequent calls, I expect the L1 cache to be disabled and the data fetched from the L2 cache, but what is happening is that the data is fetched from the factory all the time and I get these warnings on standard output
warn: Microsoft.Extensions.Caching.HybridCache
Cache backend data rejected: InvalidData.
本文标签: cNET HybridCache Disabled Local Cache returns InvalidData warningStack Overflow
版权声明:本文标题:c# - .NET HybridCache: Disabled Local Cache returns InvalidData warning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744092834a2532354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论