Web.Config文件中的WebPartCache元素

Web Part的开发者能够使用Web Part cache来存储属性值, 加速数据的取出. web part cache中的值按照单个part方式, 或者是单个用户的方式来存储, 指定的方式是调用PartCacheReadPartCacheWrite 方法.

 

你能够决定使用的cache的类型- 要么是SharePoint 数据库, 要么是ASP.NET缓存对象- 通过配置web.config文件中的WebPartCache元素. 可能的值如下:

  • None 禁止缓存.
  • Database 使用SharePoint数据库做缓存
  • CacheObject 使用ASP.NET Cache object进行缓存(默认).

举个例子, 若要使用SharePoint 数据库做缓存, 你需要创建下面的web.config的entry:

<SharePoint>
  <WebPartCache Storage="Database"/>
</SharePoint>

 

缓存细节

=========

你可以使用WebPart class的PartCacheWritePartCacheRead来管理缓存, 还有PartCacheInvalidate方法来似的部分或全部的web part cache变为非法的(比如说, 如果web part的一个属性变了). 为了在运行时获得缓存的信息, 你需要使用CacheType属性.

 

寻找cache entry的方法是使用一个键值, 这允许任意数目的name-value pair被存储在cache中.

 

使用SharePoint Database

================

During cache storage in in the database, the following occurs:

  • If parts are not personalized, Personal cache entries (a call to the PartCacheWrite method with storage set to Storage.personal) are not stored.
  • If parts are Personal (added to the page in personal view), the Shared and Personal cache entries are stored in the same place. If the PartCacheInvalidate method is called with a storage value of Shared or Personal, all the cache is cleared.

When using the database for storage, both the Shared and Personal cache are limited to 2 MB. If this limit is exceeded, no error is displayed, but the cache entry will be lost. Additionally, if the storage type is Personal, it is charged against the user's quota.

 

Any object placed in the database cache must be marked as serializable (System.SerializableAttribute).

 

使用ASP.NET cache object

=================

ASP.NET also provides caching functionality that the Web Part can use through the Cache object.

 

Caches stored using ASP.NET are limited by the size allowed by the Cache object. For more information about the Cache class, see the System.Web.Caching namespace.

 

Note  Static Web Parts can only use caching if WebPartCacheStorage is set to CacheObject. No exception is raised if the setting is Database, but no cache entry is stored. Changes to the .aspx file cause the Web Part cache to get purged for static Web Parts.

 

资料来源:

Web Parts and Caching

http://msdn.microsoft.com/en-us/library/dd585600%28office.11%29.aspx

posted on 2010-02-05 17:34  中道学友  阅读(358)  评论(0编辑  收藏  举报

导航

技术追求准确,态度积极向上