Entering content frame

Background documentation ICacheValidator Interface Locate the document in its SAP Library structure

Provides methods to control the validity of the cache:

public boolean isCacheValid(IPortalComponentRequest request, String key);

Test whether the cache is valid given a key which has been stored previously in the cache content given the method getValidationKey().

public String getValidationKey(IPortalComponentRequest request);

Computes a key that will be stored in the cache and that will pass to the method isCacheValid() at request time.

Example

This component displays an applet. The size of the applet is read from the component profile. The validator is used to invalidate the cache when these values are changing:

public class DisplayAppletComponent

   implements ICacheValidator, ICachablePortalComponent {

   public void doContent(

      IPortalComponentRequest request,

      IPortalComponentResponse response) {

 

      // Display something linked to a property

      int witdh = getAppletWidthFromProfile(request);

      int height = getAppletHeightFromProfile(request);

      displayApplet(width, height);

   }

 

   public CachingLevel getCachingLevel() {

      return CachingLevel.USER;

   }

 

   /**

    * Test whether the cache is valid or not given a key which is stored in the cache content

    *

    * @param request, the IPortalComponentRequest

    * @param key, the key which is stored

    */

   public boolean isCacheValid(IPortalComponentRequest request, String key) {

      String newKey = computeKey(width, height);

      return key.equals(newKey);

   }

 

   /**

    * Computes a key that will be stored in the cache and that will passed in the

    * method isCacheValid at each request

    *

    * @return a string, the validity key

    */

   public String getValidationKey(IPortalComponentRequest request) {

      int width = getAppletWidthFromProfile(request);

      int height = getAppletHeightFromProfile(request);

      // Computes a key with the width and height

      String key = computeKey(width, height);

      return key;

   }

 

   private String computeKey(int width, int height) {

      String key = "" + width + "|" + height;

      return key;

   }

}

 

 

Leaving content frame