How to prevent Nancy from caching

I started testing Nancy in my own host mode. So far, all is well, except for one problem that annoys me: how can I prevent my views from caching during development?

I noticed a comment that view caching should be disabled in debug mode, but it doesn't seem to work for me - I need to restart my application whenever I change the HTML.

I am using Nancy 0.10 with a built-in super simple viewer and .html files.

+6
source share
2 answers

Caching is disabled by default in debug mode. The only thing I can think of is an error in detecting debug mode while working in self-service (i.e. non-web project).

Could you try the following

  • Make sure you build 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 your view stops caching

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

+5
source

TheCodeJunkies answer works for version 1.x of Nancy.

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

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

Source: https://habr.com/ru/post/946770/


All Articles