简体   繁体   English

Net Core MemoryCache 未按请求重置

[英]Net Core MemoryCache not resetting per request

.Net Core 3.0. .Net 核心 3.0。 I have a repo where IMemoryCache gets injected.我有一个 IMemoryCache 被注入的仓库。 Repo is registered as Transient. Repo 注册为 Transient。 I would like for the cache to be cleared/reset PER request, however that is not happening.我希望缓存被清除/重置 PER 请求,但是这并没有发生。 It keeps data inserted there from prev request.它保持从上一个请求插入的数据。 How do I make it so that MemoryCache is re-created per request?如何使每个请求都重新创建 MemoryCache?

public OrganizationRepository(
   IMemoryCache cache)
{
    m_cache = cache;
    // cache still has data in entries for subsequent requests
}

Registrations:注册:

services.AddTransient<IOrganizationRepository, OrganizationRepository>();

This seems to work:这似乎有效:

services.AddScoped<MemoryCache, MemoryCache>();

then inject it as MemoryCache然后将其作为 MemoryCache 注入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM