I'm working on a webshop-like asp.net mvc 4 website with a wcf-service datalayer. My application is build with maincategories, subcategories and products. Each product can only be in one subcategory and my url's are like this:
/maincategoryname/subcategoryname/{productid}/producttitle
And the corresponding breadcrumb trail:
Home > Maincategory > Subcategory > Producttitle
I'm currently using MvcSitemapProvider to generate my navigation menu's and breadcrumbs. I'm loading all the url's as dynamic nodes without cache. This solution works for a couple of products but when I add 1000 products the sitemap takes 6,5 second to populate, wich is way too long.
I turned on caching in MvcSitemapProvider. This way the application loads much faster. But when a user adds a new product and navigates to this new product (page). The url is not yet in the sitemap file because it uses cache. This way my navigation and breadcrumbs are not generated.
My question is:
Is it possible to add a new node to the sitemap at runtime after a user adds a new product?
The accepted answer is now a little out of date. In MvcSiteMapProvider v4, there is no longer a GetCacheDescription() method in a DynamicNodeProvider. This didn't seem to work anyway.
You can now invalidate the cache manually by using the [SiteMapCacheRelease] attribute on the action methods that update the data:
[MvcSiteMapProvider.Web.Mvc.Filters.SiteMapCacheRelease]
[HttpPost]
public ActionResult Edit(int id)
{
// Update the record
return View();
}
Or by calling a static method:
MvcSiteMapProvider.SiteMaps.ReleaseSiteMap();
You also have the option now to extend the framework to supply your own cache dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With