CurrentNode should be override and cached for every request

Mar 25, 2011 at 9:34 AM


I think the performance is better if CurrentNode is cached for every request to public override SiteMapNode FindSiteMapNode(HttpContext context) because this function is call every time when refer to provider.CurrentNode.

This function is intended to find CurrentNode only, and don't required to call many times for every request

Mar 25, 2011 at 10:59 PM

Caching a complete HttpContext will be bad regarding memory. How would you go about his?

Mar 26, 2011 at 12:58 AM

we should cache only CurrentNode, not all HttpContext. This can see as:

public override SiteMapNode FindSiteMapNode(HttpContext context)
            var httpContext = new HttpContext2(context);
            var routeData = RouteTable.Routes.GetRouteData(httpContext);           

            var currentNode = FindSiteMapNode(HttpContext.Current, routeData);
            if (HttpContext.Current.Items[_currentNodeCacheKey] == null)
                HttpContext.Current.Items[_currentNodeCacheKey] = currentNode;
            return currentNode;

and override CurrentNode:

        private const string _currentNodeCacheKey = "currentNodeCacheKey";
        public override SiteMapNode CurrentNode
                return (SiteMapNode)HttpContext.Current.Items[_currentNodeCacheKey] ?? base.CurrentNode;

if not cached CurrentNode, function FindSiteMapNode(HttpContext) call every time when CurrentNode is refer (in about 4-5 functions), this make down performance when dynamic provider is used and system has a lot of node.

Apr 5, 2011 at 7:49 AM

Implemented it for v3.1.0. Thanks!