Question

There seems to be automatic caching that happens with MvcSiteMapProvider. Is there a mechanism to disable caching? We have custom caching routines written and I want to run it through those instead of relying on any built in caching mechanism.

Was it helpful?

Solution

Try to call Refresh before render menu or sitemap.

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

OTHER TIPS

In MvcSiteMapProvider v4, the cache can now be extended or replaced with your own implementation. Have a look at the following blog post that I wrote.

MvcSiteMapProvider 4.0 - Extending the Cache

Under the covers it now uses System.Runtime.Caching.ObjectCache, an abstract class that can be replaced by a cache manager of your choosing.

Looking over the source, a cache item is always created when the sitemap is built, storing the item in HttpContext.Current.Cache. The lifetime of this cache item is configured from a property in the configuration cacheDuration. If this attribute is omitted from the configuration, it defaults to 5. Try setting that configuration attribute to 0.

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

A bit hacky but who cares:

        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;
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top