3
저는 ASP.NET Core 어플리케이션에서 IMemoryCache의 표준 사용법이라고 생각합니다. startup.cs에서ASP.Net Core에서 IMemoryCache의 인스턴스를 여러 개 가져 오는 이유는 무엇입니까?
내가 가진 내 컨트롤러에서
services.AddMemoryCache();
를 내가 가지고 :
private IMemoryCache memoryCache;
public RoleService(IMemoryCache memoryCache)
{
this.memoryCache = memoryCache;
}
을하지만 내가 디버그를 통해 갈 때, 나는 각각 다른 항목 여러 메모리 캐시와 끝까지 하나. 메모리 캐시가 싱글 톤일 거라 생각했는데?
코드 샘플 업데이트 : 내가 두 번째 줄을 쳤을 때 나는 this.memoryCache 다른 항목이 포함 볼 수 있습니다
public List<FunctionRole> GetFunctionRoles()
{
var cacheKey = "RolesList";
var functionRoles = this.memoryCache.Get(cacheKey) as List<FunctionRole>;
if (functionRoles == null)
{
functionRoles = this.functionRoleDAL.ListData(orgId);
this.memoryCache.Set(cacheKey, functionRoles, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(1)));
}
}
나는 두 개의 서로 다른 브라우저에서 두 클라이언트를 실행하는 경우.
어떻게 테스트 했습니까? 더 많은 코드를 공유 할 수 있습니까? – levent
@levent 업데이트 된 질문 –