Reputation: 1185
I need to have a menu structure that changes depending on what page the user is currently viewing. Hence I need to disable caching for certain nodes as these may change for every request. How do I do this?
I have tried setting up the DynamicNode
in the following way:
var dynamicNode = new DynamicNode()
{
Title = title,
Action = actionName,
Controller = controllerName,
RouteValues = routeValues,
Attributes = attributes,
ChangeFrequency = ChangeFrequency.Always,
LastModifiedDate = DateTime.Now,
UpdatePriority = UpdatePriority.Automatic,
};
But that seems tohave no effect.
I have also set cacheDuration="0"
in the Web.config file, no effect.
I've also set the following in the GetCacheDesctription of the DynamicNodeProvider
return new CacheDescription("GuideDynamicNodeProvider")
{
AbsoluteExpiration = DateTime.Now,
};
Also with no effect.
Am I using these settings incorrectly? The documentation on this aspect is rather lacking.
Upvotes: 2
Views: 757
Reputation: 56889
Disabling caching for specific nodes is not supported. However, you can disable caching for the entire sitemap by setting the cache duration to 0
.
If what you are trying to do is refresh nodes when the data changes, you can use the SiteMapCacheReleaseAttribute
or call SiteMaps.ReleaseSiteMap()
when the data is updated.
On the other hand, if data is updated in your database from a source that is not under your control, you can implement ICacheDependency
yourself to create a SqlCacheDependency
class and then inject it using DI. Have a look at the RuntimeFileCacheDependency
class to see how that can be done.
Note that the reason the ChangeMonitor
is put into a list is so it will support the RuntimeCompositeCacheDependency
, which allows you to configure multiple cache dependencies for the same cache.
Upvotes: 1