Disable MvcSiteMapProvider Caching

It seems like automatic caching happens with MvcSiteMapProvider. Is there a mechanism to disable caching? We have custom caching routines, and I want to run them through them instead of relying on any built-in caching mechanism.

+3
source share
4 answers

Try calling Refresh before the render or sitemap menu.

<% var sm = Html.MvcSiteMap();
((MvcSiteMapProvider.DefaultSiteMapProvider)sm.Provider).Refresh(); %>
....
<%: sm.Menu(0, 1) %>
+6
source

In MvcSiteMapProvider v4, the cache can now be expanded or replaced by your own implementation. Take a look at the following blog post I wrote.

MvcSiteMapProvider 4.0 - Cache Extension

System.Runtime.Caching.ObjectCache, , .

+2

Looking back at the source, a cache element is always created when creating a site map, saving the element to HttpContext.Current.Cache. The lifetime of this cache element is configured from a property in the configuration cacheDuration. If this attribute is not specified in the configuration, it defaults to 5. Try setting this configuration attribute to 0.

<siteMap defaultProvider="MvcSiteMapProvider" enabled="true"> 
  <providers> 
    <clear /> 
    <add name="MvcSiteMapProvider" 
         type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" 
         cacheDuration="5" /> 
  </providers> 
</siteMap>
0
source

A bit of hacks, but who needs it:

        foreach (var c in from object c in HttpContext.Cache where ((System.Collections.DictionaryEntry)c).Key.ToString().Contains("__MVCSITEMAP") select c)
        {
            HttpContext.Cache.Remove(((System.Collections.DictionaryEntry)c).Key.ToString());

            break;
        }
0
source

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


All Articles