Search This Blog

Monday, April 25, 2011

Sharepoint 2007 performance tips: Part 1 : " Using PortalSiteMapProvider to retrieve list data"

One of the ways to improve performance in SharePoint 2007 while fetching data from a list is by using 'PortalSiteMapProvider'.

'PortalSiteMapProvider' provides an automatic caching infrastructure for retrieving list data. The 'GetCachedListItemsByQuery' method of PortalSiteMapProvider takes an SPQuery object as a parameter, and then checks its cache to determine whether the items already exist. If they do, the method returns the cached results. If not, it queries the list and stores the results in a cache. This approach works especially well when you are retrieving list data that does not change significantly overtime.It results in good performance.
Here's the code that illustrates the same:

       // Get the current SPWeb object.
SPWeb curWeb = SPControl.GetContextWeb(HttpContext.Current);

// Create the query.
SPQuery curQry = new SPQuery();
curQry.Query = "<Where><Eq><FieldRef Name='Registration_x0020_Type'/>
<Value Type='Text'>User</Value></Eq></Where>";

// Create an instance of PortalSiteMapProvider.
PortalSiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
PortalWebSiteMapNode pNode = ps.FindSiteMapNode(curWeb.ServerRelativeUrl) as PortalWebSiteMapNode;

// Retrieve the items.

SiteMapNodeCollection pItems = ps.GetCachedListItemsByQuery(pNode, "MyListName", curQry, curWeb);

// Enumerate through all of the matches.
foreach (PortalListItemSiteMapNode pItem in pItems)
   // Do something with each match.

However,it needs to be used with caution,as it has some limitations too:

-When data sets change frequently, the class incurs the performance cost of continually writing to the cache in addition to the costs of reading from the database.

-The PortalSiteMapProvider class uses the site collection object cache to store data. This cache has a default size of 100 MB. You can increase the size of this cache for each site collection on the object cache settings page for the site collection. But this memory is taken from the shared memory available to the application pool and can therefore affect the performance of other applications.

-Another significant limitation is that you cannot use the PortalSiteMapProvider class in applications based on Windows Forms.

No comments:

Post a Comment