Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top