I try to redefine the caching for my portal component, by using ICacheValidator. Although i implemented the functions "isCacheValid" and "getValidationKey" it seems as if these functions are not used.
At last i tried to run following simple program, where still none of the 2 functions is called.
IView and page where created according to the comments in the code. Deployment descriptor is added as well further down.
code:
package com.sap.portal.iviewtest.caching;
import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.pom.IEvent;
/*
How to implement caching functionality
1. declare an iview property for the key in portalapp.xml
2. retrieve this property for key computation
3. implement ICacheValidator
4. return custom computed key in getValidationKey()
5. check current key to computed key in isCaheValid()
remarks: - first call to component/iview will deliver NULL as pagecache key
until iview property changes
- alway change properties on iview direct noct on deltalinks
iview properties:
CacheLevel: Shared
IsolationMode: Embedded
page properties:
CacheLevel: Shared
IsolationMode: URL
*/
public class CachingIview extends AbstractPortalComponent implements ICacheValidator{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
System.out.println("doContent");
response.write(""+System.currentTimeMillis());
}
/* (non-Javadoc)
@see com.sapportals.portal.prt.component.ICacheValidator#isCacheValid(com.sapportals.portal.prt.component.IPortalComponentRequest, java.lang.String)
*/
public boolean isCacheValid(IPortalComponentRequest request, String key) {
System.out.println("KEY: "+key);
return getKeyProperty(request).equals(key);
}
/* (non-Javadoc)
@see com.sapportals.portal.prt.component.ICacheValidator#getValidationKey(com.sapportals.portal.prt.component.IPortalComponentRequest)
*/
public String getValidationKey(IPortalComponentRequest request) {
// TODO Auto-generated method stub
String key = getKeyProperty(request);
System.out.println("getValidationKey "+key);
return key;
}
/* (non-Javadoc)
@see com.sapportals.portal.prt.component.IPortalComponentInit#init(com.sapportals.portal.prt.component.IPortalComponentInitContext)
*/
public void init(IPortalComponentInitContext arg0) {
// TODO Auto-generated method stub
System.out.println("init");
}
private String getKeyProperty(IPortalComponentRequest request) {
try{
return ""+request.getComponentContext().getProfile().getProperty("KeyProperty");
}catch(Exception e){
return "";
}
}
}
portalapp.xml:
<?xml version="1.0" encoding="utf-8"?>
<application>
<application-config/>
<components>
<component name="CachingIview">
<component-config>
<property name="ClassName" value="com.sap.portal.iviewtest.caching.CachingIview"/>
<property name="SecurityZone" value="com.sap.portal.iviewtest.caching/low_safety"/>
</component-config>
<component-profile>
<property name="KeyProperty" value="0"/>
</component-profile>
</component>
</components>
<services/>
</application>