Web Part的开发者能够使用Web Part cache来存储属性值, 加速数据的取出. web part cache中的值按照单个part方式, 或者是单个用户的方式来存储, 指定的方式是调用PartCacheRead 和PartCacheWrite 方法.
你能够决定使用的cache的类型- 要么是SharePoint 数据库, 要么是ASP.NET缓存对象- 通过配置web.config文件中的WebPartCache元素. 可能的值如下:
举个例子, 若要使用SharePoint 数据库做缓存, 你需要创建下面的web.config的entry:
<SharePoint> <WebPartCache Storage="Database"/> </SharePoint>
缓存细节
=========
你可以使用WebPart class的PartCacheWrite 和PartCacheRead来管理缓存, 还有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:
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