Show TOC

ICachablePortalComponentLocate this document in the navigation structure

Use

The ICachablePortalComponent interface defines the following methods for determining the caching level and whether the cache has expired:

  • getCachingLevel : Sets the caching level, either none, shared, session or user.

                      public CachingLevel getCachingLevel(
             IPortalComponentRequest request)
                   

    Returns a CachingLevel object that represents a caching level. For example, a component can change its caching level at runtime and decide not to be cached, depending on request parameters.

    If this method is not implemented, the default implementation from AbstractPortalComponent returns the value set in the CachingLevel property.

  • hasExpired : Determines if the cache has expired. True indicates the cache has expired.

                      public boolean hasExpired(IPortalComponentRequest request,
                   long creationTime,
                   long currentTime)
    
                   

    If this method is not implemented, the default implementation from AbstractPortalComponent returns the value set in the ValidityPeriod property.

Example

The following is an example of how to use the ICachablePortalComponent interface:

            import com.sapportals.portal.prt.component.*;
 
public class MyComponent extends AbstractPortalComponent
   implements ICachablePortalComponent {
 
   public boolean hasExpired(IPortalComponentRequest request,
            long creation,
            long current) {
      if ((current - creation) > 10000) {
         return true;
      }
      return false;
   }
 
   public void doContent(IPortalComponentRequest request,
                   IPortalComponentResponse response) {
 
      if (request != null && response != null) {
          long current = java.lang.System.currentTimeMillis();
          response.write("<H2>" + new java.util.Date(current) + "</H2>");
      }
 
 
   }
}