2017-03-13 24 views
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))); 
    } 
} 

나는 두 개의 서로 다른 브라우저에서 두 클라이언트를 실행하는 경우.

+0

어떻게 테스트 했습니까? 더 많은 코드를 공유 할 수 있습니까? – levent

+0

@levent 업데이트 된 질문 –

답변

1

이유를 찾지 못했습니다. 그러나 추가 읽기 후에는 메모리 내 분산 캐시를 사용하여 IMemoryCache에서 IDistributedCache로 바뀌었고 문제는 더 이상 발생하지 않습니다. 나중에 여러 서버가 필요할 경우이 경로를 사용하면 redis 서버로 쉽게 업데이트 할 수 있다고 생각했습니다.