PortletResponseImpl response )
throws PortletException,
IOException
{
boolean debug = _log.isDebugEnabled( );
CacheDescriptor cache = _descriptor.getCacheDescriptor( request.getMode( ) );
String id = getCacheableId( cache, request, response );
PortletResponseImpl response2 = new PortletResponseImpl( this, request, response.getHttpResponse( ) );
String body = null;
CacheRegion region = null;
Cacheable cacheable;
/* Load the body from the cache */
if ( id != null )
{
if ( debug )
{
_log.debug( "Loading portlet body from the cache.id=" + id );
}
region = getCacheRegion( );
cacheable = region.get( id );
if ( cacheable != null )
{
if ( !isDirty( request ) )
{
if ( debug )
{
_log.debug( "...Portlet body found in the cache" );
}
body = ( String ) cacheable.getData( );
}
else
{
if ( debug )
{
_log.debug( "...Portlet dirty. expiring the portlet body" );
}
cacheable.expire( );
body = null;
}
}
}
else
{
if ( debug )
{
_log.debug( "Caching not supported" );
}
}
if ( body == null )
{
/* Generate the body */
if ( debug )
{
_log.debug( "Generating the portlet body" );
}
_portlet.service( request, response2 );
body = response2.getBuffer( ).toString( );
/* Cache the body */
if ( region != null )
{
if ( debug )
{
_log.debug( "...Caching the portlet body" );
}
cacheable = new CacheableImpl( id, body, 1000 * cache.getExpires( ) );
_cacheRegion.put( cacheable );
}
}
/* Bye */