/** * Decorate the given Cache, if necessary. * @param cache the raw Cache object, based on the configuration of this FactoryBean * @return the (potentially decorated) cache object to be registered with the CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
/** * Decorate the given Cache, if necessary. * @param cache the raw Cache object, based on the configuration of this FactoryBean * @return the (potentially decorated) cache object to be registered with the CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
PopulatingCache(Ehcache s, EntryCreator<K, V> entryCreator) { creator = entryCreator; final CacheEntryFactory f = new CacheEntryFactory() { @SuppressWarnings("unchecked") @Override public Object createEntry(Object key) throws Exception { return creator.createEntry((K) key); } }; self = new net.sf.ehcache.constructs.blocking.SelfPopulatingCache(s, f); }
PopulatingCache(Ehcache s, EntryCreator<K, V> entryCreator) { creator = entryCreator; final CacheEntryFactory f = new CacheEntryFactory() { @SuppressWarnings("unchecked") @Override public Object createEntry(Object key) throws Exception { return creator.createEntry((K) key); } }; self = new net.sf.ehcache.constructs.blocking.SelfPopulatingCache(s, f); }
/** * @param coursesByTermCache The cache to use for courses by term */ @Required public void setCoursesByTermCache(Ehcache coursesByTermCache) { this.coursesByTermCache = new SelfPopulatingCache(coursesByTermCache, new CacheEntryFactory() { @Override public Object createEntry(Object key) throws Exception { final CacheKey scopedKey = (CacheKey)key; return coursesDao.getCoursesByTerm(scopedKey.key); } }); }
/** * @param termListCache The cache to use for term lists */ @Required public void setTermListCache(Ehcache termListCache) { this.termListCache = new SelfPopulatingCache(termListCache, new CacheEntryFactory() { @Override public Object createEntry(Object key) throws Exception { final CacheKey scopedKey = (CacheKey)key; return coursesDao.getTermList(scopedKey.key); } }); }
@Autowired public void setResourceCache( @Qualifier("org.apereo.portal.utils.cache.resource.CachingResourceLoader") Ehcache resourceCache) { this.resourceCache = new SelfPopulatingCache(resourceCache, this.entryFactory); }
@Autowired public void setResourceCache( @Qualifier("org.apereo.portal.utils.cache.resource.CachingResourceLoader") Ehcache resourceCache) { this.resourceCache = new SelfPopulatingCache(resourceCache, this.entryFactory); }
@Autowired public void setUserViews( @Qualifier("org.apereo.portal.layout.dlm.FragmentActivator.userViews") Ehcache userViews) { this.userViews = new SelfPopulatingCache( userViews, new CacheEntryFactory() { @Override public Object createEntry(Object key) throws Exception { final UserViewKey userViewKey = (UserViewKey) key; // Check if there was an exception the last time a load attempt was // made and re-throw final net.sf.ehcache.Element exceptionElement = userViewErrors.get(userViewKey); if (exceptionElement != null) { throw (Exception) exceptionElement.getObjectValue(); } try { return activateFragment(userViewKey); } catch (Exception e) { userViewErrors.put(new net.sf.ehcache.Element(userViewKey, e)); throw e; } } }); }
@Autowired @Qualifier("org.apereo.portal.RDBMUserIdentityStore.userLockCache") public void setUserLockCache(Ehcache userLockCache) { this.userLockCache = new SelfPopulatingCache(userLockCache, key -> new SerializableObject()); }
@Autowired @Qualifier("org.apereo.portal.RDBMUserIdentityStore.userLockCache") public void setUserLockCache(Ehcache userLockCache) { this.userLockCache = new SelfPopulatingCache(userLockCache, key -> new SerializableObject()); }
public void afterPropertiesSet() throws Exception mVersionCache = new SelfPopulatingCache(versionCache, new CacheEntryFactory(){ mEnvironmentCache = new SelfPopulatingCache(environmentCache, new CacheEntryFactory(){ mHostCache = new SelfPopulatingCache(hostCache, new CacheEntryFactory(){ mWebappCache = new SelfPopulatingCache(webappCache, new CacheEntryFactory(){ mClientHostCache = new SelfPopulatingCache(clientHostCache, new CacheEntryFactory(){ mUserCache = new SelfPopulatingCache(userCache, new CacheEntryFactory(){ mSessionCache = new SelfPopulatingCache(sessionCache, new CacheEntryFactory(){ mURLCache = new SelfPopulatingCache(urlCache, new CacheEntryFactory(){ mHitResultCache = new SelfPopulatingCache(hitResultCache, new CacheEntryFactory(){ mDelayTypeCache = new SelfPopulatingCache(delaytypeCache, new CacheEntryFactory(){
/** * Decorate the given Cache, if necessary. * @param cache the raw Cache object, based on the configuration of this FactoryBean * @return the (potentially decorated) cache object to be registered with the CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
/** * Decorate the given Cache, if necessary. * @param cache the raw Cache object, based on the configuration of this FactoryBean * @return the (potentially decorated) cache object to be registered with the CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
/** * Decorate the given Cache, if necessary. * * @param cache the raw Cache object, based on the configuration of this * FactoryBean * @return the (potentially decorated) cache object to be registered with the * CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
/** * Decorate the given Cache, if necessary. * * @param cache the raw Cache object, based on the configuration of this * FactoryBean * @return the (potentially decorated) cache object to be registered with the * CacheManager */ protected Ehcache decorateCache(Ehcache cache) { if (this.cacheEntryFactory != null) { if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) { return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory); } else { return new SelfPopulatingCache(cache, this.cacheEntryFactory); } } if (this.blocking) { return new BlockingCache(cache); } return cache; }
/** * 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 a new {@link SelfPopulatingCache} and corresponding {@link CacheEntryFactory} */ protected SelfPopulatingCacheTracker createSelfPopulatingCache(Ehcache cache, int timeout, DecoratedCacheType type, long refreshinterval) { final SelfPopulatingCache selfPopulatingCache; final ThreadLocal<MethodInvocation> invocationLocal; switch (type) { case REFRESHING_SELF_POPULATING_CACHE: { final RefreshingCacheEntryFactory cacheEntryFactory = new RefreshingCacheEntryFactory(); selfPopulatingCache = new RefreshingSelfPopulatingCache(cache, cacheEntryFactory, scheduler, executor, refreshinterval); invocationLocal = cacheEntryFactory.entryFactory; break; } case SELF_POPULATING_CACHE: { final ThreadLocalCacheEntryFactory cacheEntryFactory = new ThreadLocalCacheEntryFactory(); selfPopulatingCache = new SelfPopulatingCache(cache, cacheEntryFactory); invocationLocal = cacheEntryFactory.entryFactory; break; } default: { throw new IllegalArgumentException("DecoratedCacheType " + type + " is not a supported self-populating type"); } } selfPopulatingCache.setTimeoutMillis(timeout); return new SelfPopulatingCacheTracker(selfPopulatingCache, invocationLocal); }
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; }