How to Prevent Nancy From Caching Views

℡╲_俬逩灬. 提交于 2019-12-23 08:54:50

问题


I've started testing out Nancy in self-host mode. So far, so good apart from one issue that's irking me: How do I prevent it from caching my views while developing?

I did notice a comment that view caching is supposed to be disabled in Debug mode but it doesn't seem to be working for me - I have to restart my application whenever I make a change to the HTML.

I'm using Nancy 0.10 with the built-in super simple view engine and .html files.


回答1:


Caching is disabled by default in debug-mode. The only thing I can think of is that there might be a bug on the debug-mode detection while running in a self-host (i.e a non web-project).

Could you please try the following

  • Make sure your are building in debug-mode and check the value of StaticConfiguration.DisableCaches and let me know if it is true or false
  • Explicitly try setting StaticConfiguration.DisableCaches to true and see if it stops caching your view

If DisableCaches is true then it ignores to use the cache in the DefaultViewCache type https://github.com/NancyFx/Nancy/blob/master/src/Nancy/ViewEngines/DefaultViewCache.cs#L30




回答2:


TheCodeJunkies answer works for version 1.x of Nancy.

For 2.x of Nancy the runtimeViewDiscovery and runtimeViewUpdates properties handle if views are cached or not. This can be changed in your NancyBootstrapper class, like so:

public class NancyBootstrapper : DefaultNancyBootstrapper
{
    public override void Configure(INancyEnvironment environment)
    {
        base.Configure(environment);
        environment.Views(runtimeViewDiscovery: true, runtimeViewUpdates: true);
    }
}


来源:https://stackoverflow.com/questions/9534021/how-to-prevent-nancy-from-caching-views

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!