c# - 为什么 Filedepency 上的 ExpireToken 不清除 CacheEntry?
问题描述
我使用 IMemoryCache 缓存 Razorpages 网站中的不同对象。我使用以下方法添加它们:
public void AddEntryToCache(string key, object obj)
{
var fileProvider = new PhysicalFileProvider(@"c:\mycachefolder");
var changeToken = fileProvider.Watch("cacheclearfile.txt");
// entry should be cleared when txt-file changes
MemoryCacheEntryOptions options = new MemoryCacheEntryOptions();
options.AddExpirationToken(changeToken);
// _cache is the injected IMemoryCache-Object
_cache.Set(key, obj, options);
}
这个方法是我在 Startup 中添加的一个类的一部分:
services.AddSingleton<UtilCache>();
我添加了一个文件依赖。但是当我更改文件的内容时,缓存条目不会被清除并且仍然保留在缓存中。
我错过了什么?
解决方案
推荐阅读
- amazon-web-services - AWS 实例上的权限被拒绝(公钥)
- asp.net-core - 如何在带有 IdentityServer 的 ASP.NET Core 5.0 应用程序中实现验证码?
- javascript - Babel 更改异步错误
- css - SCSS 变量未全局应用
- docker - 使用可选参数化分支从 git 构建 Docker
- python - 如何在 APIRouter(不是 FastAPI)中对异常进行单元测试
- java - 在 Java 中存储千克的最佳数据类型是什么?
- android - 未解决的参考: Parcelable Kotlin
- django - Django 表单给出“str”对象没有属性“_meta”
- regex - 使用正则表达式将日期列转换为列“开始”和“结束”