DeleteOldOnAccessCache extends AbstractReportContentCache { @Override public void cleanupCurrentSession() { final IPentahoSession session = PentahoSessionHolder.getSession(); final List<String> key = Collections.unmodifiableList( Arrays.asList( SEGMENT, createKey( session.getName() ) ) ); final ICacheBackend backend = getBackend(); backend.purgeSegment( key, ( k, m ) -> true ); } DeleteOldOnAccessCache( final ICacheBackend backend );  DeleteOldOnAccessCache(); void setDaysToLive( final long daysToLive ); @Override boolean put( final String key, final IReportContent value ); @Override boolean put( final String key, final IReportContent value,  Map<String, Serializable> metaData ); @Override IReportContent get( final String key ); @Override Map<String, Serializable> getMetaData( String key ); @Override void cleanup(); @Override void cleanupCurrentSession(); static final String TIMESTAMP; static final int MILLIS_IN_DAY; static final String ANONYMOUS; }
@Test public void testCleanupCurrentSession() throws Exception { final StandaloneSession bill = new StandaloneSession( "bill" ); final StandaloneSession steve = new StandaloneSession( "steve" ); PentahoSessionHolder.setSession( bill ); final DeleteOldOnAccessCache cache = new DeleteOldOnAccessCache( fileSystemCacheBackend ); cache.setDaysToLive( 1L ); cache.put( SOME_KEY, SOME_VALUE ); assertNotNull( cache.get( SOME_KEY ) ); PentahoSessionHolder.setSession( steve ); assertNull( cache.get( SOME_KEY ) ); cache.put( SOME_KEY, SOME_VALUE ); assertNotNull( cache.get( SOME_KEY ) ); cache.cleanupCurrentSession(); assertNull( cache.get( SOME_KEY ) ); PentahoSessionHolder.setSession( bill ); assertNotNull( cache.get( SOME_KEY ) ); cache.cleanupCurrentSession(); assertNull( cache.get( SOME_KEY ) ); }