The ICacheDiscriminator interface 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:
getCacheDiscriminator: Returns a string for labeling the component's content when placed into the cache.
Syntax
public String getCacheDiscriminator(IPortalComponentRequest request)
A component displaying weather reports can cache content for each city.
Syntax
package com.sapportals.portal.prt.test.component; import com.sapportals.portal.prt.component.*; import com.sapportals.portal.prt.event.IPortalRequestEvent; public class WeatherComponent implements ICacheDiscriminator { private final String SELECTED_CITY = "SelectedCity"; private final String CITY_PROPERTY = "City"; public void doContent(IPortalComponentRequest request, IPortalComponentResponse response) { if (request != null && response != null) { String cityName = (String) request.getNode().getValue(CITY_PROPERTY); } // Add content here } /** * Stores the selected city in the component profile */ public void doSelect(IPortalComponentRequest request, IPortalRequestEvent event) { if (request != null) { String cityName = (String) request.getParameter("SELECTED_CITY"); request.getNode().putValue(CITY_PROPERTY, cityName); } } /** * Uses the city name as the cache discriminator. */ public String getCacheDiscriminator( IPortalComponentRequest request) { if (request != null) { String cityName = (String) request.getNode().getValue(CITY_PROPERTY); return cityName; } } }