저는 asp.net Core에서 CacheItemRemovedCallback과 동일한 메소드를 찾고있는 첫 번째 패스 Google 검색을 수행했으며 지금까지는 비어 있습니다. 캐시 무효화를 사용하여 일부 핵심 웹 응용 프로그램에서 의사 서비스/타이머 역할을합니다.ASP.Net Core 2.0의 CacheItemRemovedCallback
당신이 현명한 인터넷 신이 어떤 식 으로든 내 방식을 고수 할 수 있다면 좋을 것입니다.
업데이트 : 시작시 올바르게 호출되는 것으로 보이는 OWIN 클래스를 만들었지 만 캐시 무효화는 결코 호출되지 않습니다. 나는 놓쳤다.
public class OwinCacheTimer
{
private readonly RequestDelegate next;
private IMemoryCache cache;
public OwinCacheTimer(RequestDelegate next, IMemoryCache memoryCache)
{
this.cache = memoryCache;
this.next = next;
SetCache(this);
}
public void SetCache(object o)
{
/* do work */
MemoryCacheEntryOptions options = new MemoryCacheEntryOptions();
options.AbsoluteExpiration = DateTime.Now.AddSeconds(21);
options.SlidingExpiration = TimeSpan.FromSeconds(20);
options.RegisterPostEvictionCallback(ExpiredCallback, o); // <- this doesn't fire
IMemoryCache x = ((OwinCacheTimer)o).cache;
/* setting whateve, just so something expires */
x.Set<string>("timestamp", DateTime.Now.ToString(), options);
}
public void ExpiredCallback(object key, object value, EvictionReason reason, object state)
{
SetCache(state);
}
public async Task Invoke(HttpContext context)
{
this.BeginInvoke(context);
await this.next.Invoke(context);
this.EndInvoke(context);
}
private void BeginInvoke(HttpContext context)
{
// Do custom work before controller execution
}
private void EndInvoke(HttpContext context)
{
// Do custom work after controller execution
}
}
좋아처럼 그것은이 문서가 유사한 개념을 논의하기 위해 보인다 보이지만, 캐싱 컨트롤러에 바인딩처럼은 변경 될 수있는, 보이는 캐시 유효성 검사를 영구적 인 서비스/타이머 작업의 일종으로 사용할 수 있습니다. 나는 그것과 놀고 볼 것이다. http://www.binaryintellect.net/articles/a7d9edfd-1f86-45f8-a668-64cc86d8e248.aspx – infocyde
위의 캐싱 예제는 컨트롤러 용이지만 OWIN 클래스에 해킹하려고 시도했습니다. 어쩌면 그럴 수 없습니다. – infocyde