}
private CdfRunJsDashboardWriteResult
getDashboardWriteResultFromCache( DashboardCacheKey cacheKey, String cdeFilePath ) throws FileNotFoundException {
IReadAccess userContentAccess = Utils.getSystemOrUserReadAccess( cdeFilePath );
// 1. Try to obtain dashboard from cache
Element cacheElement;
try {
synchronized ( this._ehCacheLock ) {
cacheElement = this._ehCache.get( cacheKey );
}
} catch ( CacheException ex ) {
_logger.info( "Cached dashboard render invalidated, re-rendering." );
return null;
}
// 2. In the cache?
if ( cacheElement == null ) {
_logger.debug( "Dashboard render is not in cache." );
return null;
}
CdfRunJsDashboardWriteResult dashWrite = (CdfRunJsDashboardWriteResult) cacheElement.getValue();
// 3. Get the template file
String templPath = cacheKey.getTemplate();
// 4. Check if cache item has expired
// Cache is invalidated if the dashboard or template have changed since
// the cache was loaded, or at midnight every day,
// because of dynamic generation of date parameters.
Calendar cal = Calendar.getInstance();
cal.set( Calendar.HOUR_OF_DAY, 00 );
cal.set( Calendar.MINUTE, 00 );
cal.set( Calendar.SECOND, 1 );
// The date at which the source Dashboard object
// was loaded from disk, not the date at which the DashResult was written.
Date dashLoadedDate = dashWrite.getLoadedDate();
boolean cacheExpired = cal.getTime().after( dashLoadedDate );
if ( cacheExpired ) {
_logger.debug( "Cached dashboard render expired, re-rendering." );
return null;
}
boolean cacheInvalid =
( userContentAccess.getLastModified( cdeFilePath ) > dashLoadedDate.getTime() )
|| ( userContentAccess.fileExists( templPath )
&& userContentAccess.getLastModified( templPath ) > dashLoadedDate.getTime() );
if ( cacheInvalid ) {
_logger.info( "Cached dashboard render invalidated, re-rendering." );
return null;
}