Show TOC

Background documentationICachablePortalComponent Locate this document in the navigation structure

 

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.

    Syntax Syntax

    1. public CachingLevel getCachingLevel(
               IPortalComponentRequest request)
    End of the code.

    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.

    Syntax Syntax

    1. public boolean hasExpired(IPortalComponentRequest request,
                     long creationTime,
                     long currentTime)
      
    End of the code.

    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:

Syntax Syntax

  1. 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>");
          }
    
    
       }
    }
    
End of the code.