this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
private void addOrReplaceDecoratedCache(final Ehcache underlyingCache, final Ehcache decoratedCache) { if (decoratedCache.getName().equals(underlyingCache.getName())) { this.replaceCacheWithDecoratedCache(underlyingCache, decoratedCache); } else { addDecoratedCache(decoratedCache); } }
public void setCache(Ehcache cache) { BlockingCache ref; if (!(cache instanceof BlockingCache)) { ref = new BlockingCache(cache); cache.getCacheManager().replaceCacheWithDecoratedCache(cache, new BlockingCache(cache)); } else { ref = (BlockingCache)cache; } this.cache = ref; }
@Component public class CacheInitConfigurer implements InitializingBean { @Autowired private CacheManager cacheManager; @Autowired private MyCacheDecoratorFactory decoratorFactory; @Override public void afterPropertiesSet() throws Exception { final Ehcache myCache = cacheManager.getEhcache("MY_CACHE"); cacheManager.replaceCacheWithDecoratedCache(myCache, decoratorFactory.createDefaultDecoratedEhcache(myCache, null)); } }
private <K, V> Ehcache getLoadingCache(final @Nonnull String name, final @Nonnull CacheSettings settings, final CacheLoader<K, V> loader) { final Ehcache ehcache = getCleanCache(name, settings); final SynchronizedLoadingCacheDecorator decorator; if (ehcache instanceof SynchronizedLoadingCacheDecorator) { decorator = (SynchronizedLoadingCacheDecorator) ehcache; } else { decorator = new SynchronizedLoadingCacheDecorator(ehcache); delegate.replaceCacheWithDecoratedCache(ehcache, decorator); } return new LoadingCache<>(decorator, loader); }
private void addOrReplaceDecoratedCache(final Ehcache underlyingCache, final Ehcache decoratedCache) { if (decoratedCache.getName().equals(underlyingCache.getName())) { this.replaceCacheWithDecoratedCache(underlyingCache, decoratedCache); } else { addDecoratedCache(decoratedCache); } }
private void addOrReplaceDecoratedCache(final Ehcache underlyingCache, final Ehcache decoratedCache) { if (decoratedCache.getName().equals(underlyingCache.getName())) { this.replaceCacheWithDecoratedCache(underlyingCache, decoratedCache); } else { addDecoratedCache(decoratedCache); } }
private void addOrReplaceDecoratedCache(final Ehcache underlyingCache, final Ehcache decoratedCache) { if (decoratedCache.getName().equals(underlyingCache.getName())) { this.replaceCacheWithDecoratedCache(underlyingCache, decoratedCache); } else { addDecoratedCache(decoratedCache); } }
protected void createCache(String name) { synchronized (this.getClass()) { cacheManager.addCache(name); final Ehcache cache = cacheManager.getEhcache(name); // default EHCache is non blocking. Since our impl always requires blocking cache wrap it here. final BlockingCache newBlockingCache = new BlockingCache(cache); newBlockingCache.setTimeoutMillis(getBlockingTimeout()); cacheManager.replaceCacheWithDecoratedCache(cache, newBlockingCache); } }
/** * Sets the non-null {@link Ehcache} used to back this {@link TokenStore}. * * @param cache * a non-null {@link Ehcache} */ public void setCache(Ehcache cache) { BlockingCache ref; if (!(cache instanceof BlockingCache)) { ref = new BlockingCache(cache); cache.getCacheManager().replaceCacheWithDecoratedCache(cache, new BlockingCache(cache)); } else { ref = (BlockingCache) cache; } this.cache = ref; }
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
public EhBlockingCache(final String id) { super(id); if (!CACHE_MANAGER.cacheExists(id)) { CACHE_MANAGER.addCache(this.id); Ehcache ehcache = CACHE_MANAGER.getEhcache(this.id); BlockingCache blockingCache = new BlockingCache(ehcache); CACHE_MANAGER.replaceCacheWithDecoratedCache(ehcache, blockingCache); } }
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
/** * Replace the cache with a BlockingCache decorated one if this has not been done yet. * The cacheLoaderTimeoutMillis of the original cache will be used as the timeoutMillis of the BlockingCache. * @param ehcache the original cache * @return a BlockingCache wrapping the original one */ protected BlockingCache replaceWithBlockingCacheIfNot(Ehcache ehcache){ if (ehcache instanceof BlockingCache){ return (BlockingCache) ehcache; } BlockingCache blockingCache = new BlockingCache(ehcache); blockingCache.setTimeoutMillis((int)ehcache.getCacheConfiguration().getCacheLoaderTimeoutMillis()); cacheManager.replaceCacheWithDecoratedCache(ehcache, blockingCache); return blockingCache; }
/** * Replace the cache with a SelfPopulatingCache decorated one if this has not been done yet. * The cacheLoaderTimeoutMillis of the original cache will be used as the timeoutMillis of the BlockingCache. * @param ehcache the original cache * @param factory the cache entry value factory * @return a BlockingCache wrapping the original one */ protected SelfPopulatingCache replaceWithSelfPopulatingCacheIfNot(Ehcache ehcache, CacheEntryFactory factory){ if (ehcache instanceof SelfPopulatingCache){ return (SelfPopulatingCache) ehcache; } SelfPopulatingCache selfPopulatingCache = new SelfPopulatingCache(ehcache, factory); selfPopulatingCache.setTimeoutMillis((int)ehcache.getCacheConfiguration().getCacheLoaderTimeoutMillis()); cacheManager.replaceCacheWithDecoratedCache(ehcache, selfPopulatingCache); return selfPopulatingCache; }
/** * Create and return a reference to {@link Cache} object. * * @return instance of {@link Cache}. */ public static Cache createInstance(String name, net.sf.ehcache.CacheManager cacheManager) { net.sf.ehcache.Ehcache cache = cacheManager.getEhcache(name); if(cache == null) { String error = "createInstance cache: " + name + " is null"; throw new CfgRuntimeException(GlobalErrIds.FT_CACHE_NOT_CONFIGURED, error); } BlockingCache blockingCache = new BlockingCache(cache); blockingCache.setTimeoutMillis(60000); cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache); return new EhCacheImpl(name, blockingCache); } }
getCacheManager().replaceCacheWithDecoratedCache(cache, newBlockingCache);
getCacheManager( ).replaceCacheWithDecoratedCache( cache, newBlockingCache );
private static CacheManager buildCache(CacheConfig config) { CacheManager manager; if (config.getConfigurationPath() != null) { manager = CacheManager.newInstance(config.getConfigurationPath()); } else { Configuration cacheConfig = new Configuration(); cacheConfig.setMaxBytesLocalDisk((long) config.getDiskCacheSize()); cacheConfig.setMaxBytesLocalHeap((long) config.getHeapSize()); CacheConfiguration defaultCacheConfiguration = new CacheConfiguration() .persistence( new PersistenceConfiguration() .strategy( PersistenceConfiguration.Strategy .LOCALTEMPSWAP)); cacheConfig.defaultCache(defaultCacheConfiguration); if (config.isUseDiskCache()) { DiskStoreConfiguration diskConfig = new DiskStoreConfiguration(); diskConfig.setPath(config.getCacheDirectory().toAbsolutePath().toString()); cacheConfig.diskStore(diskConfig); } manager = new CacheManager(cacheConfig); manager.addCache(DEFAULT_CACHE); Cache cache = manager.getCache(DEFAULT_CACHE); SelfPopulatingCache populatingCache = new SelfPopulatingCache(cache, new S3ChunkEntryFactory(config)); manager.replaceCacheWithDecoratedCache(cache, populatingCache); } return manager; }