views:

231

answers:

4

Hi,

I have a piece of data, a simple string containing the server name that the SharePoint solution is deployed to, that I retrieve from a configuration store in a helper method in a common DLL used throughout my solution. This helper method is used throughout my custom pages and web parts, to build a number of URLs, etc.

I would like to persist this string, and prevent it being repeatedly retrieved from the configuration store. My Sharepoint installation is currently on a single server, but will be migrated to a SharePoint server farm in the near future, so simply determining the server name of the current request, etc isn't an option. I have looked at caching as described in the best practices for SharePoint, but unless I use a coherent cache like NCache or Velocity/AppFrabric, I will again have issues when the move to server farm occurs. Given that this is a single string, adding a full caching solution such as Velocity seems like overkill.

Does anyone have any suggestions on the best way to persist this data? Am I missing something obvious here?

Thanks, MagicAndi

+3  A: 

Look into using the Property bag that is exposed by all major SharePoint objects to persist information. i.e.

SPFarm.Properties
SPWebApplication.Properties
SPSite.Properties
zincorp
+1  A: 

You could:

  • Store the string in web.config. You can programatically change the web.config on all the farm's webservers using a SPWebConfigModification
  • Store the string in a SharePoint list and read from it. I usually use this solution because I have more to store than a single string. The list is 'available' on all web servers and I cache its values in an ASP.NET cache object. Someone made this concept into a solution you can download and install: SPConfigStore
ArjanP
Arjan, thanks for your answer. I am already storing the value in the SPConfigStore list; I simply don't want to have multiple calls to retrieve the value from the config store list. In terms of using the ASP.NET cache object, what issues have you encountered using the cache on a server farm?
MagicAndi
But SPConfigStore already does that for you... you can download the sourcecode and verify the actual mechanism but it caches all the values from the SharePoint list in memory so it doesn't have to do that again... no need for you to cache it again. It comes with a mechanism for flushing that cache, via a file dependancy. I don't use this mechanism for fast-changing values, all is pretty much static. But if I do have to make an update I run a script that alters that file dependancy file on all servers and the cache is flushed. I've found this more reliable than the included eventhandler.
ArjanP
ArjanP, thanks, just checked the http://www.codeplex.com/SPConfigStore site, and it states that the Config Store list items are cached in memory. Accepting as answer.
MagicAndi
A: 

This article may be of use to those looking at storing configuration data in SharePoint:

MagicAndi
+1  A: 

You can use SPPersisted to do such kind of operations.

Carol
Hi Carol, thanks for answering. The SPPersistedObject class looks to be extremely useful. +1
MagicAndi