가 좋아,이 부트 스트 래퍼에서 사용자 지정 ViewCache
을 추가하여 작동하도록 관리 :
public class MyBootstrapper : DefaultNancyBootstrapper
{
#if DEBUG
protected override IRootPathProvider RootPathProvider
{
get
{
// this sets the root folder to the VS project directory
// so that any template updates in VS will be picked up
return new MyPathProvider();
}
}
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
return NancyInternalConfiguration.WithOverrides(
x =>
{ x.ViewCache = typeof(MyViewCache); });
}
}
#endif
새로운 ViewCache
단지 모든 요청에 템플릿을 다시로드 :
public class MyViewCache : IViewCache
{
...
public TCompiledView GetOrAdd<TCompiledView>(
ViewLocationResult viewLocationResult, Func<ViewLocationResult, TCompiledView> valueFactory)
{
//if (viewLocationResult.IsStale())
// {
object old;
this.cache.TryRemove(viewLocationResult, out old);
// }
return (TCompiledView)this.cache.GetOrAdd(viewLocationResult, x => valueFactory(x));
}
}
은 어떻게 든 viewLocationResult.IsStale()
가되었다 항상 false
을 반환합니다.
기본적으로
이 그냥보기의 마지막 업데이트 시간을 비교 FileSystemViewLocationResult
의 인스턴스이지만, 타임 스탬프 this.lastUpdated
는 DefaultViewCache
에서 IsStale()
를 호출하기 전에 업데이트되고, 그래서 템플릿은 캐시에서 제거되지 않았다
public override bool IsStale()
{
return this.lastUpdated != this.fileSystem.GetLastModified(this.fileName);
}
좋아 보이지만 완벽하지는 않습니다. FileSystemViewLocationResult를 어떻게 오버라이드합니까? –