Friday 5 November 2010

Dropdownbox population options for custom SharePoint applications

Problem: I need to populate combo boxes and drop down list boxes on a customised SharePoint page using a web part.  The web part has 5 of these lists that are populated choice fields.

Initial Hypothesis: I could use the Enum generated by Linq to SharePoint for the choice field options but to change the available options would require me to re-generate the SPMetal proxy.  I could use lookup lists and then use Linq to SharePoint but this is pretty heavy for simple choice columns.  So I chose to use the SP Server-side Object Model, this is not too heavy as it is only looking up the columns and looping thru the choices however I have 5 drop down lists doing this repeatedly for a lot of users.  So although it is working it could be better if the results were cached for a minute.  This would allow choice options to be change and the using a cache duration of 1 minute, the longest the wait would be is 60 seconds before users see the updated lists.

Resolution: I cached my list item collections, on the page I had 5 choice fields.  By adding the caching I am getting a 36% performance increase in my Page Request response time.  So not as good a return as I was expecting but still a considerable improvement. 

Test Information:
I used a sample of 10 items per request type.  The 10 pages requested each for the cached list item collections and the un-cached version.  I excluded the 1st page request for warm up. 
All the results were pretty consistent.
The testing was done on a local development machine.
Developer Dashboard showing improved response times using cacheing.
Code to cache list item collections:
HttpContext.Current.Cache.Insert(keyname, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration)

0 comments:

Post a Comment