@Override protected void addNativeCache(String cacheName) { nativeCacheManager.addCache(cacheName); }
CacheManager cacheManager = CacheManager.getInstance(); int oneDay = 24 * 60 * 60; Cache memoryOnlyCache = new Cache("name", 200, false, false, oneDay, oneDay); cacheManager.addCache(memoryOnlyCache);
private void createIfMissing(String group) { //double-checked synchronization is broken in Java, but this should work just fine. if (cacheManager.getCache(group) == null) { try { cacheManager.addCache(group); } catch (Exception ignore) { logger.warn(ignore.getMessage()); } } }
import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; public class InitializationListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); CacheManager singletonManager = CacheManager.create(); Cache memoryOnlyCache = new Cache("dbCache", 100, false, true, 86400,86400); singletonManager.addCache(memoryOnlyCache); cache = singletonManager.getCache("dbCache"); ctx.setAttribute("dbCache", cache ); } }
@Bean(name = "goCache") public GoCache createCache() { CacheManager cacheManager = CacheManager.newInstance(new Configuration().name(getClass().getName())); Cache cache = new Cache(cacheConfiguration); cacheManager.addCache(cache); return new GoCache(cache, transactionSynchronizationManager); }
protected Cache getRegion(String regionName) { Cache region = getCacheManager().getCache(regionName); if (region == null) { getCacheManager().addCache(regionName); region = getCacheManager().getCache(regionName); } return region; }
protected Ehcache createCache(String regionName) { switch ( missingCacheStrategy ) { case CREATE_WARN: SecondLevelCacheLogger.INSTANCE.missingCacheCreated( regionName, ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation() ); cacheManager.addCache( regionName ); return cacheManager.getEhcache( regionName ); case CREATE: cacheManager.addCache( regionName ); return cacheManager.getEhcache( regionName ); case FAIL: throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" ); default: throw new IllegalStateException( "Unsupported missing cache strategy: " + missingCacheStrategy ); } }
private static Ehcache createCacheIfRequired() { final CacheManager instance = CacheManager.newInstance(new Configuration().name(CachingSubjectDnX509PrincipalExtractor.class.getName())); synchronized (instance) { if (!instance.cacheExists(CACHE_NAME)) { instance.addCache(new Cache(cacheConfiguration())); } return instance.getCache(CACHE_NAME); } }
/** * Loads an existing EhCache from the cache manager, or starts a new cache if one is not found. * * @param name the name of the cache to load/create. */ public final <K, V> Cache<K, V> getCache(String name) throws CacheException { if (log.isTraceEnabled()) { log.trace("Acquiring EhCache instance named [" + name + "]"); } try { net.sf.ehcache.Ehcache cache = ensureCacheManager().getEhcache(name); if (cache == null) { if (log.isInfoEnabled()) { log.info("Cache with name '{}' does not yet exist. Creating now.", name); } this.manager.addCache(name); cache = manager.getCache(name); if (log.isInfoEnabled()) { log.info("Added EhCache named [" + name + "]"); } } else { if (log.isInfoEnabled()) { log.info("Using existing EHCache named [" + cache.getName() + "]"); } } return new EhCache<K, V>(cache); } catch (net.sf.ehcache.CacheException e) { throw new CacheException(e); } }
private static Ehcache createCacheIfRequired(String cacheName) { final CacheManager instance = CacheManager.newInstance(new Configuration().name(cacheName)); synchronized (instance) { if (!instance.cacheExists(cacheName)) { instance.addCache(new net.sf.ehcache.Cache(cacheConfiguration(cacheName))); } return instance.getCache(cacheName); } }
private static Ehcache createCacheIfRequired(String cacheName) { final CacheManager instance = CacheManager.newInstance(new Configuration().name(cacheName)); synchronized (instance) { if (!instance.cacheExists(cacheName)) { instance.addCache(new Cache(cacheConfiguration(cacheName))); } return instance.getCache(cacheName); } }
this.cacheManager.addCache(rawCache);
@BeforeClass public static void initCacheManaer() { cacheManager = CacheManager.create(); cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30)); }
@BeforeClass public static void initCacheManaer() { cacheManager = CacheManager.create(); cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30)); }
@BeforeClass public static void initCacheManaer() { cacheManager = CacheManager.create(); cacheManager.addCache(new Cache("castickets", 500, false, false, 30, 30)); }
private synchronized Cache getHeap() { if (heap == null) { if (CacheManager.getInstance().cacheExists("hydrated-cache")) { heap = CacheManager.getInstance().getCache("hydrated-cache"); } else { CacheConfiguration config = new CacheConfiguration("hydrated-cache", 0).eternal(true).overflowToDisk(false).maxElementsInMemory(100000); Cache cache = new Cache(config); CacheManager.create().addCache(cache); heap = cache; } } return heap; }
private synchronized Cache getHeap() { if (offHeap == null) { if (CacheManager.getInstance().cacheExists("hydrated-offheap-cache")) { offHeap = CacheManager.getInstance().getCache("hydrated-offheap-cache"); } else { CacheConfiguration config = new CacheConfiguration("hydrated-offheap-cache", 500).eternal(true).overflowToOffHeap(true).maxMemoryOffHeap("1400M"); Cache cache = new Cache(config); CacheManager.create().addCache(cache); offHeap = cache; } } return offHeap; }
this.cacheManager.addCache(rawCache);
cacheManager.addCache(testCache);
@Before public void setup() { cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests") .defaultCache(new CacheConfiguration("default", 100))); nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100)); cacheManager.addCache(nativeCache); cache = new EhCacheCache(nativeCache); }