ServiceCacheFactory implements PushDownFactory { public Cache<CachedService.CacheKey, CachedService> getCache( ServiceCache serviceCache, String dataServiceName ) throws CacheException { Optional<Cache<CachedService.CacheKey, CachedService>> cache = getCache( dataServiceName ); if ( cache.isPresent() ) { return cache.get(); } return getPentahoCacheTemplateConfiguration( serviceCache ) .createCache( cacheName( dataServiceName ), CachedService.CacheKey.class, CachedService.class ); } ServiceCacheFactory( PentahoCacheManager cacheManager, ExecutorService executorService ); @Override String getName(); @Override Class<ServiceCache> getType(); @Override ServiceCache createPushDown(); @Override ServiceCacheOverlay createOverlay(); ServiceCacheController createController(); ListeningExecutorService getExecutorService(); PentahoCacheManager getCacheManager(); Cache<CachedService.CacheKey, CachedService> getCache( ServiceCache serviceCache, String dataServiceName ); PentahoCacheTemplateConfiguration getPentahoCacheTemplateConfiguration( ServiceCache serviceCache ); Optional<Cache<CachedService.CacheKey, CachedService>> getCache( String dataServiceName ); String cacheName( String dataServiceName ); ServiceObserver createObserver( DataServiceExecutor executor ); CachedServiceLoader createCachedServiceLoader( CachedService cachedService ); CachedServiceLoader createCachedServiceLoader( Supplier<Iterator<RowMetaAndData>> supplier ); Iterable<String> getTemplateNames(); Map<String, String> getPropertiesByTemplateName( String templateName ); Map<CachedService.CacheKey, ServiceObserver> getRunningServices(); static final String CACHE_PREFIX; }
@Test public void testGetCache() throws Exception { assertThat( serviceCacheFactory.getCache( DATA_SERVICE_NAME ).isPresent(), is( false ) ); when( cacheManager.getCache( cacheName(), CachedService.CacheKey.class, CachedService.class ) ).thenReturn( cache ); ServiceCache serviceCache = serviceCacheFactory.createPushDown(); assertThat( serviceCacheFactory.getCache( DATA_SERVICE_NAME ), is( Optional.of( cache ) ) ); assertThat( serviceCacheFactory.getCache( serviceCache, DATA_SERVICE_NAME ), is( cache ) ); }