Caches an SPWeb for the duration of the HTTP request.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
'Declaration Public Sub CacheWeb ( _ key As String, _ web As SPWeb _ ) 'Usage Dim instance As SPContext Dim key As String Dim web As SPWeb instance.CacheWeb(key, web)
public void CacheWeb( string key, SPWeb web )
A unique identifier associated with this cached item. This key can be used to retrieve the web or remove it.
The web to cache.
This method is only recommended for certain scenarios. There are a few important considerations.
In general, webs are only meant to be used for a short periods. Keeping an SPWeb around for long periods of time can cause performance problems for the entire server. Caching a web here is a tradeoff; in most cases it is better to close and open the web multiple times. Only in cases where it is likely that the web will be re-used frequently throughout the entire request, it is better to cache it.
Remember that webs have internal caches. For example, a web caches lists, list items and fields. The longer the web is open, the more likely these caches become invalid due to others writing to these lists, list items and fields. As such, if webs are held open for long periods of time, it becomes more likely that write conflict exceptions will occur.
Therefore, only use this method to cache webs that will be opened frequently and throughout the life of the request. The decision to cache a web should be carefully considered and only a small number of webs should be subjected to caching per request.