配置 Portlet 的高速缓存策略

Portlet 的片段高速缓存要求您在 cachespec.xml 文件中定义高速缓存策略(在 Portlet Web 应用程序归档 (WAR) 文件中或全局性地定义高速缓存策略)。如果没有定义适用于特定 Portlet 的高速缓存策略,那么不会高速缓存该 portlet。

WebSphere® Application Server 高速缓存策略在定义高速缓存标识方面具有很大的灵活性,并提供大量与各个 Portlet 的特定需求相匹配的失效规则。您可以定义的高速缓存策略未必要与按照 Java Portlet 规范定义的高速缓存行为一致。 以下章节给出了一些建议,指导您如何开发 cachespec.xml 文件的功能,以定义符合规范的高速缓存策略。

高速缓存到期。Portlet 在 portlet.xml 部署描述符的 <expiration-cache> 元素中定义高速缓存到期时间。如果不存在该此元素,或者包含零值,那么不高速缓存 portlet。只能在部署描述符中定义 Portlet 的高速缓存到期时间;在 cachespec.xml 文件中指定的所有高速缓存超时值均无效。

高速缓存范围。无论是否应该在所有用户之间共享 Portlet 内容,也无论 Portlet 内容是否包含特定于用户的信息且必须针对每个用户单独进行高速缓存,都在 portlet.xml 部署描述符的 <caching-scope> 元素中定义 Portlet。要在您的高速缓存策略定义中维持此设置,请在高速缓存键中包含 com.ibm.wsspi.portletcontainer.user_cache_scope 属性,包括以下高速缓存关键组件:
<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>
此属性包含以下值:
  • 定义公共高速缓存范围的 Portlet 中的值 public
  • 定义专用高速缓存范围的 Portlet 中当前登录的用户标识。
  • 如果定义专用高速缓存范围的 Portlet 中没有用户登录,那么是 Null(匿名)。

如果您要高速缓存 Portlet 内容以进行匿名访问(即使是在定义专用高速缓存范围的 Portlet 中),请向高速缓存关键组件添加 <required>false</required>。这表示所有的匿名浏览访问都将检索相同的高速缓存内容。

Portlet 生命周期方法。Java Portlet 规范定义 Portlet 中运行的四个生命周期阶段:操作、事件、呈递和资源。只有呈递和资源阶段会产生内容;操作和事件阶段调用 Portlet 活动,但不会生成内容而且一定不要对其进行高速缓存。portlet 调用的生命周期阶段可在 javax.portlet.lifecycle_phase请求属性中找到。检查生命周期是否正确,方法是包含以下高速缓存关键组件:
<component id="javax.portlet.lifecycle_phase" type="attribute">
	<value>RENDER_PHASE</value>
</component>
此高速缓存关键组件只高速缓存到 Portlet 的呈递请求。通过添加 RESOURCE_PHASE 来高速缓存其他的资源请求。 在许多情况下,最好的方法是为资源请求定义单独的 <cache-id> 元素。资源标识可用于 com.ibm.wsspi.portletcontainer.resource_id 请求属性,用来高速缓存资源请求中的关键生成。
请求参数。Portlet 通常可以显示多个视图。 呈递参数区分要显示哪个视图。每种参数组合都会形成不同的 Portlet 视图。需要单独高速缓存所有视图;所以,通常要在高速缓存键中包含完整的请求参数映射。com.ibm.wsspi.portletcontainer.all_parameters 属性完整请求参数映射的内容的唯一值,该映射可以和以下高速缓存关键组件一起使用:
<component id="com.ibm.wsspi.portletcontainer.all_parameters" type="attribute">
	<required>false</required>
</component>
如果您为特定的 Portlet 编写高速缓存策略,并且准确地知道哪个请求参数定位哪个 Portlet 视图,那么较为有效的方法是使用高速缓存键中特定的 <parameter> 元素来仅高速缓存最重要的 Portlet 视图。

其他高速缓存关键组件。根据您的使用方案,您可能需要在高速缓存键中包含其他信息(如果返回的内容与其相关,例如 Portlet 方式和窗口状态,或多语言门户网站中的键语言环境)。在支持不同标记类型的多设备门户网站中,返回的内容类型还应该作为高速缓存键的一部分。portlet 的内容类型可用于 com.ibm.wsspi.portletcontainer.response_contenttype 请求属性中。

高速缓存无效。操作和事件请求到 Portlet 的 Java Portlet 规范状态必须使所有当前高速缓存的内容无效。 portlet 高速缓存定义通常允许同一时间高速缓存某个 Portlet 的多个视图。要使它们全部无效,请使用 cachespec.xml 的依赖性标识机制。

为(某操作将使其无效的)所有视图定义普通的依赖性标识。普通标识通常只包括 Portlet 窗口标识和用户范围,因此 Portlet 操作不影响其他用户的专用高速缓存条目:
<dependency-id>action
	<component id="" type="portletWindowId"/>
	<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>
</dependency-id>
定义无效规则,该规则重复依赖性标识并添加当前生命周期方法作为条件。这对在条件部分上包含 ignore-value 属性十分必要。生命周期属性不得包含在返回的无效标识中,这是因为无效标识必须完全匹配前面指定的依赖性标识。
<invalidation>action
	<component id="" type="portletWindowId"/>
	<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>
	<component id="javax.portlet.lifecycle_phase" type="attribute" ignore-value="true">
		<value>ACTION_PHASE</value>
		<value>EVENT_PHASE</value>
	</component>
</invalidation>
遵循同样的模式,在高速缓存策略中为个别的 Portlet 指定更为复杂的无效策略(例如,您可以只使 Portlet 视图子集的根据请求参数确定的特定操作无效)。以下示例代码描述了符合 Java Portlet 规范所定义的行为的普通高速缓存配置:
Sample cachespec.xml file

<?xml version="1.0" ?>
<!DOCTYPE cache SYSTEM "cachespec.dtd">
<cache>
	<cache-entry>
		<class>portlet</class>
		<name>MyPortlet</name>
		<property name="consume-subfragments">true</property>
		<cache-id>
			<component id="" type="portletWindowId"/>
			<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>

			<component id="" type="portletWindowState">
			<!-- minimized portlets are not cached -->
			<not-value>minimized</not-value>
		</component>
		<component id="" type="portletMode"/>

		<component id="" type="locale"/>
		<component id="com.ibm.wsspi.portletcontainer.response_contenttype" type="attribute"/>

		<component id="com.ibm.wsspi.portletcontainer.all_parameters" type="attribute">
			<required>false</required>
		</component>

		<component id="javax.portlet.lifecycle_phase" type="attribute">
			<value>RENDER_PHASE</value>
		</component>
	</cache-id>

	<dependency-id>action
		<component id="" type="portletWindowId"/>
		<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>
	</dependency-id>

	<invalidation>action
		<component id="" type="portletWindowId"/>
		<component id="com.ibm.wsspi.portletcontainer.user_cache_scope" type="attribute"/>
		<component id="javax.portlet.lifecycle_phase" type="attribute" ignore-value="true">
			<value>ACTION_PHASE</value>
			<value>EVENT_PHASE	</value>
		</component>
	</invalidation>
	
	</cache-entry>
</cache>

指示主题类型的图标 参考主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rdyn_portletcachepolicy
文件名:rdyn_portletcachepolicy.html