/** * Create a raw Cache object based on the configuration of this FactoryBean. */ protected Cache createCache() { return new Cache(this); }
/** * Create a raw Cache object based on the configuration of this FactoryBean. */ protected Cache createCache() { return new Cache(this); }
private static void createCacheForOkHTTP() { Cache cache = null; cache = new Cache(getDirectory(), 1024 * 1024 * 10); okHttpClient.setCache(cache); } // returns the file to store cached details private File getDirectory() { return new File(“location”); }
CacheManager cacheManager = CacheManager.getInstance(); int oneDay = 24 * 60 * 60; Cache memoryOnlyCache = new Cache("name", 200, false, false, oneDay, oneDay); cacheManager.addCache(memoryOnlyCache);
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); }
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); } }
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); } }
@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; }
new Cache(new CacheConfiguration("test", 0).//
@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); }
int cacheSize = 10 * 1024 * 1024; // 10 MiB File cacheDir = new File(context.getCacheDir(), "HttpCache"); Cache cache = new Cache(cacheDir, cacheSize); OkHttpClient client = new OkHttpClient.Builder() .cache(cache) .build();
@Bean public Cache cache() { CacheManager cacheManager = cacheManager(); Cache apiKeyCache = cacheManager.getCache(CACHE_NAME); if (apiKeyCache == null) { LOGGER.warn("EHCache cache for " + CACHE_NAME + " not found. Fallback to default EHCache configuration"); CacheConfiguration cacheConfiguration = new CacheConfiguration(CACHE_NAME, 1000); cacheManager.addCache(new Cache(cacheConfiguration)); } return cacheManager.getCache(CACHE_NAME); }
@Bean public Cache cache() { CacheManager cacheManager = cacheManager(); Cache apiKeyCache = cacheManager.getCache(API_KEY_CACHE_NAME); if (apiKeyCache == null) { LOGGER.warn("EHCache cache for apikey not found. Fallback to default EHCache configuration"); CacheConfiguration cacheConfiguration = new CacheConfiguration(API_KEY_CACHE_NAME, 1000); cacheManager.addCache(new Cache(cacheConfiguration)); } return cacheManager.getCache(API_KEY_CACHE_NAME); }
/** * Create a cache given a cache configuration * * @param cacheConfiguration */ final Ehcache createCache(CacheConfiguration cacheConfiguration) { CacheConfiguration configClone = cacheConfiguration.clone(); // make sure all caches use the same classloader that the CacheManager is configured to use configClone.setClassLoader(configuration.getClassLoader()); Ehcache cache = new Cache(configClone, null, null); cache = applyCacheExceptionHandler(configClone, cache); return cache; }