Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm currently storing a few values in the SPWeb.AllProperties hashtable. But I'm thinking of adding even more data into it. Before I start using it more and more though, I wondered if using AllProperties is efficient or not. Does it cache the values in memory or have to go to the db each time? Basically, does accessing SPWeb.AllProperties have any real performance penalties. Similarly, if I access SPWeb.ParentWeb.AllProperties, does that cause any performance(db) hit?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The various property bags are backed by Hashtable objects, except for SPWeb.Properties which is a StringDictionary (essentially a strongly-typed, non-generic Hashtable). SPWeb.AllProperties is a Hashtable and is prefered to AllProperties (it also does not force lowercase key values).

The performance of all these containers is excellent (see for example here). None of them are commited to the database until you call .Update() on their parent object.

The drawback for the property bags is that they are strings, and thus need [de]serialization to store anything other than text although there is no hard limit on the size of strings you store (at least no limit in the Hashtable object itself).

See here for a specific performance test of the property bags vs SPPersistedObject.

See also Managing Custom Configuration Options for a SharePoint Application.

Update: Your comment forced me to dig into the SPWeb object a bit. Wow. It's actually pretty badly implemented, SPWeb being backed by an old, inefficient COM object. Thanks for updating my assumptions.

So first, Properties and AllProperties are backed on the same object, the difference being only that AllProperties include a ToLower() on the keys when enumerating through everything to load the Array.

Second, yes Array. For SPWeb the property bag is returned as a HashTable but it's actually a simple array of object[,], completely enumerated and loaded into a HashTable directly in the .Properties get { }, so yes it's loaded completely. Fortunately for subsequent calls the getter keeps its value locally in the SPWeb object, but that also means there is an entire local copy in every SPWeb object. .Properties is loaded into a HashTable, .AllProperty is loaded into a StringDictionnary, both from SPWeb.Request.GetWebMetainfo(this.Url) (which is COM).

So, again, do NOT use it to store very large objects. It's made for short property strings.

SPFarm.Properties is a little better (SPFarm is not a COM object). This one is a true HashTable, as SPFarm is a SPPersistedObject, itself derived from SPAutoSerializingObject. So SPFarm.Update() drops all of the object into DB, including it's HashTable. Again here, the entire property bag resides in memory as soon as you create the SPFarm object, and for the object's lifetime.

share|improve this answer
    
Thanks for the info. I already knew that AllProperties was a Hashtable, but what I didn't know and still don't know is how and when this get's populated and if using it causes any extra overhead. Is it populated on every request? Is it populated regardless of weather I access it directly? If I access SPWeb.ParentWeb.AllProperties, would that cause any extra trip to the db or is it already in the request context. These are things that I don't seem to be able to find out. Can you give me any insight on these questions? –  TehOne Mar 8 '12 at 8:06
    
What do you mean "how and when this gets populated"? It takes memory storage (size of items + a small amount for internal housekeeping), there's not much more overhead but don't store 2Gb of data in them. –  Louis Mar 8 '12 at 11:42
    
I mean that I assume that data stored there must be kept in the DB. So I'm just not sure when or how the data gets pulled from the DB. Is it on every request, regardless of if I access the properties or not. And is it cached or kept in memory so that if I access it repeatedly in different web controls, I'm not causing extra trips back to the db. My main concern is just that I don't want to cause extra trips to the db, and if I was going to cause extra trips to the db, then I was just going to cache the data myself instead of pulling from AllProperties each time. –  TehOne Mar 8 '12 at 17:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.