Reputation: 13931
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.
Upvotes: 4
Views: 3223
Reputation: 56899
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.
Upvotes: 2
Reputation: 165
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;
}
Upvotes: 0
Reputation: 86
Try to call Refresh before render menu or sitemap.
<% var sm = Html.MvcSiteMap();
((MvcSiteMapProvider.DefaultSiteMapProvider)sm.Provider).Refresh(); %>
....
<%: sm.Menu(0, 1) %>
Upvotes: 6
Reputation: 61599
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>
Upvotes: 0