ICacheDiscriminator

TheICacheDiscriminatorinterface enables you to save different caches for a component, each with a different label, or cache discriminator. When another request is made for the component, the portal requests the cache discriminator from the component and then retrieves cached content if one of the caches has the specified cache discriminator.

The interface defines the following method:

getCacheDiscriminatorReturns a string for labeling the component’s content when placed into the cache.

publicString getCacheDiscriminator(IPortalComponentRequest request)

Example

A component displaying weather reports can cache content for each city.

packagecom.sapportals.portal.prt.test.component;

importcom.sapportals.portal.prt.component.*;

importcom.sapportals.portal.prt.event.IPortalRequestEvent;

publicclassWeatherComponentimplementsICacheDiscriminator{

privatefinalStringSELECTED_CITY="SelectedCity"

privatefinalStringCITY_PROPERTY="City"

publicvoiddoContent(IPortalComponentRequestrequest,

IPortalComponentResponseresponse){

if(request!=null&&response!=null){

StringcityName= (String) request.getNode().getValue(CITY_PROPERTY);

}

// Add content here

}

/**

*Storestheselectedcityinthecomponentprofile

*/

publicvoiddoSelect(IPortalComponentRequestrequest,

IPortalRequestEventevent){

if(request!=null){

StringcityName= (String)request.getParameter("SELECTED_CITY");

request.getNode().putValue(CITY_PROPERTY,cityName);

}

}

/**

*Uses the city name as thecachediscriminator.

*/

publicStringgetCacheDiscriminator( IPortalComponentRequestrequest){

if(request!=null){

StringcityName= (String)request.getNode().getValue(CITY_PROPERTY);

returncityName;

}

}

}