2012-09-04 3 views
1

많은 테스트를했는데 MemoryCache 인스턴스가 일정 시간 후에 처리되고 Get 메서드를 호출 할 때 항상 null을 반환합니다. PollingInterval 이후라고 생각합니다. MemoryCache가 Disposed 상태에 있음 Magually

는 새로운 웹 애플리케이션을 시작하고이 코드를 작성할 수 있습니다 시뮬레이션 :

private static MemoryCache mem = new MemoryCache("MyCache"); 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     string key = "MyKey"; 
     mem.Set(key, "MyValue", new CacheItemPolicy() {AbsoluteExpiration = DateTimeOffset.Now.AddDays(1), Priority = CacheItemPriority.NotRemovable}); 
     LtrValue.Text = mem.Get(key) as string; 
    } 

는 나는이 작동하는 것 같다 30 시간 pollingInterval에 구성했습니다.

나는 AppDomain을 언로드 할 수 있다고 생각하지만, 일부 조사 후 나는 그것을 생각하지는 :

1) MSDN은 ASP.NET에 대한 MemoryCache를 사용하여 말한다 : http://msdn.microsoft.com/en-us/library/ff477235(v=vs.100).aspx 그리고 ASP.NET을 말한다 4 캐시는 ObjectCache로 작성됩니다.

ASP.NET 4에서 캐싱은 ObjectCache 클래스를 사용하여 구현됩니다.

2) AppDomain 언로드는 statics 변수를 재설정하여 새 MemoryCache 인스턴스를 만듭니다.

3) 메모리 캐시가 (내 컴파일 된 소스를 보았습니다.) 내 테스트에서 AppDomain 언로드에 이벤트를 연결했는데 메모리 캐시가 처리되지 않았습니다.

참고 :

MSDN 포럼에서 동일한 게시물 : http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/1233ffb3-6480-431b-94ca-1190f96cf5f6

http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/0a666d5e-9bda-47bd-8dd3-98d32eb5fe60

MemoryCache Empty : Returns null after being set

System.Runtime.Caching.MemoryCache strange behavior?

MemoryCache empty just after adding an object

MemoryCache does not obey memory limits in configuration

+0

중복 가능성을 .NET으로 포트를 백업하기 위해 노력하고 있습니다 (http://stackoverflow.com/questions/7422859/memorycache-disposed-in-web-application) –

+0

Scott Hanselman은 .Net4에서 사용자에게 영향을 줄 수있는 버그를보고합니다. http://stackoverflow.com/questions/7422859/memorycache 웹 응용 프로그램에서 배포 됨 –

답변

관련 문제