我正在尝试在加载 razorpage 时将一堆列表添加到 MemoryCache 中。列表已添加到缓存中,但在我重新加载页面时似乎丢失了
我在这里做错了什么?我是否误解了缓存的工作原理?
启动
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMemoryCache();
}
Razorpage 构造函数
private IMemoryCache _cache;
public TimesModel(IMemoryCache memoryCache){
_cache = memoryCache;
}
Razorpage ongetAsync
public async Task OnGetAsync() {
if (_cache.Get<List<CommonListTable>>("listR2") == null) {
_sqlLoads++;
_cache.Set("listR2", CommonData.listR2, cacheEntryOptions);
}
}
谢谢
托马斯