net.sf.ehcache.CacheManager Java Examples
The following examples show how to use
net.sf.ehcache.CacheManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EHCacheProvider.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 7 votes |
public ResourceDataCache createDataCache() { try { final CacheManager manager = getCacheManager(); synchronized( manager ) { if ( manager.cacheExists( DATA_CACHE_NAME ) == false ) { final Cache libloaderCache = new Cache( DATA_CACHE_NAME, // cache name 500, // maxElementsInMemory false, // overflowToDisk false, // eternal 600, // timeToLiveSeconds 600, // timeToIdleSeconds false, // diskPersistent 120 ); // diskExpiryThreadIntervalSeconds manager.addCache( libloaderCache ); return new EHResourceDataCache( libloaderCache ); } else { return new EHResourceDataCache( manager.getCache( DATA_CACHE_NAME ) ); } } } catch ( CacheException e ) { logger.debug( "Failed to create EHCache libloader-data cache", e ); return null; } }
Example #2
Source File: EhCacheSupportTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCacheManagerConflict() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.setCacheManagerName("myCacheManager"); assertEquals(CacheManager.class, cacheManagerFb.getObjectType()); assertTrue("Singleton property", cacheManagerFb.isSingleton()); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0); Cache myCache1 = cm.getCache("myCache1"); assertTrue("No myCache1 defined", myCache1 == null); EhCacheManagerFactoryBean cacheManagerFb2 = new EhCacheManagerFactoryBean(); cacheManagerFb2.setCacheManagerName("myCacheManager"); cacheManagerFb2.afterPropertiesSet(); fail("Should have thrown CacheException because of naming conflict"); } catch (CacheException ex) { // expected } finally { cacheManagerFb.destroy(); } }
Example #3
Source File: ClientCachePopulationRule.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void before() throws SQLException { super.before(); CacheManager.getInstance().clearAll(); controlTagCache.init(); processCache.init(); dataTagCache.init(); equipmentCache.init(); aliveTimerCache.init(); commFaultTagCache.init(); subEquipmentCache.init(); alarmCache.init(); ruleTagCache.init(); commandTagCache.init(); deviceClassCache.init(); deviceCache.init(); }
Example #4
Source File: EhcacheFactory.java From MeetingFilm with Apache License 2.0 | 6 votes |
static Cache getOrAddCache(String cacheName) { CacheManager cacheManager = getCacheManager(); Cache cache = cacheManager.getCache(cacheName); if (cache == null) { synchronized(locker) { cache = cacheManager.getCache(cacheName); if (cache == null) { log.warn("无法找到缓存 [" + cacheName + "]的配置, 使用默认配置."); cacheManager.addCacheIfAbsent(cacheName); cache = cacheManager.getCache(cacheName); log.debug("缓存 [" + cacheName + "] 启动."); } } } return cache; }
Example #5
Source File: EhCacheSupportTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testEhCacheFactoryBeanWithSelfPopulatingCache() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); cacheFb.setCacheManager(cm); cacheFb.setCacheName("myCache1"); cacheFb.setCacheEntryFactory(key -> key); assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class); cacheFb.afterPropertiesSet(); Ehcache myCache1 = cm.getEhcache("myCache1"); assertTrue(myCache1 instanceof SelfPopulatingCache); assertEquals("myKey1", myCache1.get("myKey1").getObjectValue()); } finally { cacheManagerFb.destroy(); } }
Example #6
Source File: EnchachePooFactory.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
@Override public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) { CacheManager cacheManager = CacheManager.create(); Cache enCache = cacheManager.getCache(poolName); if (enCache == null) { CacheConfiguration cacheConf = cacheManager.getConfiguration() .getDefaultCacheConfiguration().clone(); cacheConf.setName(poolName); if (cacheConf.getMaxEntriesLocalHeap() != 0) { cacheConf.setMaxEntriesLocalHeap(cacheSize); } else { cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize)); } cacheConf.setTimeToIdleSeconds(expiredSeconds); Cache cache = new Cache(cacheConf); cacheManager.addCache(cache); return new EnchachePool(poolName,cache,cacheSize); } else { return new EnchachePool(poolName,enCache,cacheSize); } }
Example #7
Source File: WebEhCacheManagerFacotryBean.java From Lottery with GNU General Public License v2.0 | 6 votes |
public void afterPropertiesSet() throws IOException, CacheException { log.info("Initializing EHCache CacheManager"); Configuration config = null; if (this.configLocation != null) { config = ConfigurationFactory .parseConfiguration(this.configLocation.getInputStream()); if (this.diskStoreLocation != null) { DiskStoreConfiguration dc = new DiskStoreConfiguration(); dc.setPath(this.diskStoreLocation.getFile().getAbsolutePath()); try { config.addDiskStore(dc); } catch (ObjectExistsException e) { log.warn("if you want to config distStore in spring," + " please remove diskStore in config file!", e); } } } if (config != null) { this.cacheManager = new CacheManager(config); } else { this.cacheManager = new CacheManager(); } if (this.cacheManagerName != null) { this.cacheManager.setName(this.cacheManagerName); } }
Example #8
Source File: CachePopulationRule.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void before() throws SQLException { super.before(); CacheManager.getInstance().clearAll(); controlTagCache.init(); processCache.init(); dataTagCache.init(); equipmentCache.init(); aliveTimerCache.init(); commFaultTagCache.init(); subEquipmentCache.init(); alarmCache.init(); ruleTagCache.init(); commandTagCache.init(); deviceClassCache.init(); deviceCache.init(); }
Example #9
Source File: AppModule.java From jerseyoauth2 with MIT License | 6 votes |
@Override protected void configureServlets() { bind(IAccessTokenStorageService.class).to(CachingAccessTokenStorage.class); bind(IClientService.class).to(DatabaseClientService.class); bind(IConfiguration.class).to(Configuration.class); bind(IRSConfiguration.class).to(Configuration.class); bind(IAuthorizationFlow.class).to(TestAuthorizationFlow.class); bind(IUserService.class).to(DefaultPrincipalUserService.class); bind(ITokenGenerator.class).to(MD5TokenGenerator.class); bind(IClientIdGenerator.class).to(UUIDClientIdGenerator.class); bind(EntityManagerFactory.class).toProvider(new PersistenceProvider()); bind(CacheManager.class).toProvider(new DefaultCacheManagerProvider()); serve("/oauth2/auth").with(AuthorizationServlet.class); serve("/oauth2/accessToken").with(IssueAccessTokenServlet.class); filter("/oauth2/*").through(StrictSecurityFilter.class); }
Example #10
Source File: EhCacheSupportTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testBlankCacheManager() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.setCacheManagerName("myCacheManager"); assertEquals(CacheManager.class, cacheManagerFb.getObjectType()); assertTrue("Singleton property", cacheManagerFb.isSingleton()); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0); Cache myCache1 = cm.getCache("myCache1"); assertTrue("No myCache1 defined", myCache1 == null); } finally { cacheManagerFb.destroy(); } }
Example #11
Source File: EHCacheManagerHolder.java From steady with Apache License 2.0 | 6 votes |
public static CacheManager getCacheManager(Bus bus, URL configFileURL) { CacheManager cacheManager = null; if (configFileURL == null) { //using the default cacheManager = findDefaultCacheManager(bus); } if (cacheManager == null) { if (configFileURL == null) { cacheManager = CacheManager.create(); } else { cacheManager = CacheManager.create(configFileURL); } } AtomicInteger a = COUNTS.get(cacheManager.getName()); if (a == null) { COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger()); a = COUNTS.get(cacheManager.getName()); } if (a.incrementAndGet() == 1) { //System.out.println("Create!! " + cacheManager.getName()); } return cacheManager; }
Example #12
Source File: CacheWrapperImpl.java From olat with Apache License 2.0 | 6 votes |
/** * @param cache */ protected CacheWrapperImpl(String cacheName, CacheConfig config) { this.cacheName = cacheName; this.config = config; this.cachemanager = CacheManager.getInstance(); // now we need a cache which has appropriate (by configuration) values for cache configs such as ttl, tti, max elements and so on. // next line needed since cache can also be initialized through ehcache.xml if (cachemanager.cacheExists(cacheName)) { this.cache = cachemanager.getCache(cacheName); log.warn("using cache parameters from ehcache.xml for cache named '" + cacheName + "'"); } else { this.cache = config.createCache(cacheName); try { cachemanager.addCache(this.cache); } catch (CacheException e) { throw new OLATRuntimeException("Problem when initializing the caches", e); } } }
Example #13
Source File: EHCacheManagerHolder.java From steady with Apache License 2.0 | 6 votes |
public static CacheManager getCacheManager(Bus bus, URL configFileURL) { CacheManager cacheManager = null; if (configFileURL == null) { //using the default cacheManager = findDefaultCacheManager(bus); } if (cacheManager == null) { if (configFileURL == null) { cacheManager = CacheManager.create(); } else { cacheManager = CacheManager.create(configFileURL); } } AtomicInteger a = COUNTS.get(cacheManager.getName()); if (a == null) { COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger()); a = COUNTS.get(cacheManager.getName()); } if (a.incrementAndGet() == 1) { //System.out.println("Create!! " + cacheManager.getName()); } return cacheManager; }
Example #14
Source File: EHCacheProvider.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public ResourceFactoryCache createFactoryCache() { try { final CacheManager manager = getCacheManager(); synchronized( manager ) { if ( manager.cacheExists( FACTORY_CACHE_NAME ) == false ) { final Cache libloaderCache = new Cache( FACTORY_CACHE_NAME, // cache name 500, // maxElementsInMemory false, // overflowToDisk false, // eternal 600, // timeToLiveSeconds 600, // timeToIdleSeconds false, // diskPersistent 120 ); // diskExpiryThreadIntervalSeconds manager.addCache( libloaderCache ); return new EHResourceFactoryCache( libloaderCache ); } else { return new EHResourceFactoryCache( manager.getCache( FACTORY_CACHE_NAME ) ); } } } catch ( CacheException e ) { logger.debug( "Failed to create EHCache libloader-factory cache", e ); return null; } }
Example #15
Source File: CacheWrapperImpl.java From olat with Apache License 2.0 | 6 votes |
/** * @param cache */ protected CacheWrapperImpl(String cacheName, CacheConfig config) { this.cacheName = cacheName; this.config = config; this.cachemanager = CacheManager.getInstance(); // now we need a cache which has appropriate (by configuration) values for cache configs such as ttl, tti, max elements and so on. // next line needed since cache can also be initialized through ehcache.xml if (cachemanager.cacheExists(cacheName)) { this.cache = cachemanager.getCache(cacheName); log.warn("using cache parameters from ehcache.xml for cache named '" + cacheName + "'"); } else { this.cache = config.createCache(cacheName); try { cachemanager.addCache(this.cache); } catch (CacheException e) { throw new OLATRuntimeException("Problem when initializing the caches", e); } } }
Example #16
Source File: TicketRegistryDecoratorTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Test public void testEhCacheTicketRegistryWithClearPass() { final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100); final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100); final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml")); manager.addCache(serviceTicketsCache); manager.addCache(ticketGrantingTicketCache); final Map<String, String> map = new HashMap<String, String>(); final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache); final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map); assertNotNull(decorator); assertEquals(decorator.serviceTicketCount(), 0); assertEquals(decorator.sessionCount(), 0); manager.removalAll(); manager.shutdown(); }
Example #17
Source File: CachePopulationRule.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void before() throws SQLException { super.before(); CacheManager.getInstance().clearAll(); controlTagCache.init(); processCache.init(); dataTagCache.init(); equipmentCache.init(); aliveTimerCache.init(); commFaultTagCache.init(); subEquipmentCache.init(); alarmCache.init(); ruleTagCache.init(); commandTagCache.init(); deviceClassCache.init(); deviceCache.init(); }
Example #18
Source File: EhcacheFactory.java From springboot-admin with Apache License 2.0 | 6 votes |
static Cache getOrAddCache(String cacheName) { CacheManager cacheManager = getCacheManager(); Cache cache = cacheManager.getCache(cacheName); if (cache == null) { synchronized(locker) { cache = cacheManager.getCache(cacheName); if (cache == null) { log.warn("无法找到缓存 [" + cacheName + "]的配置, 使用默认配置."); cacheManager.addCacheIfAbsent(cacheName); cache = cacheManager.getCache(cacheName); log.debug("缓存 [" + cacheName + "] 启动."); } } } return cache; }
Example #19
Source File: CacheUtil.java From ml-blog with MIT License | 5 votes |
public static void deleteAll() { CacheManager cacheManager = SpringContext.getBeanByType(CacheManager.class); String[] cacheNames = cacheManager.getCacheNames(); for (String cacheName : cacheNames) { Cache cache = cacheManager.getCache(cacheName); cache.removeAll(); cache.flush(); } }
Example #20
Source File: EhCacheManagerFactoryBean.java From spring-analysis-note with MIT License | 5 votes |
@Override public void afterPropertiesSet() throws CacheException { if (logger.isInfoEnabled()) { logger.info("Initializing EhCache CacheManager" + (this.cacheManagerName != null ? " '" + this.cacheManagerName + "'" : "")); } Configuration configuration = (this.configLocation != null ? EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration()); if (this.cacheManagerName != null) { configuration.setName(this.cacheManagerName); } if (this.shared) { // Old-school EhCache singleton sharing... // No way to find out whether we actually created a new CacheManager // or just received an existing singleton reference. this.cacheManager = CacheManager.create(configuration); } else if (this.acceptExisting) { // EhCache 2.5+: Reusing an existing CacheManager of the same name. // Basically the same code as in CacheManager.getInstance(String), // just storing whether we're dealing with an existing instance. synchronized (CacheManager.class) { this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName); if (this.cacheManager == null) { this.cacheManager = new CacheManager(configuration); } else { this.locallyManaged = false; } } } else { // Throwing an exception if a CacheManager of the same name exists already... this.cacheManager = new CacheManager(configuration); } }
Example #21
Source File: EhCacheService.java From wisdom with Apache License 2.0 | 5 votes |
/** * Creates the EhCache-based implementation of the Cache Service. */ @Validate public void start() { Boolean enabled = configuration.getBooleanWithDefault("ehcache.enabled", true); if (!enabled) { return; } File config = new File(configuration.getBaseDir(), CUSTOM_CONFIGURATION); final ClassLoader original = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); if (config.isFile()) { manager = CacheManager.create(config.getAbsolutePath()); } else { URL url = EhCacheService.class.getClassLoader().getResource(INTERNAL_CONFIGURATION); if (url != null) { manager = CacheManager.create(url); } else { throw new ExceptionInInitializerError("Cannot instantiate EhCache, " + "cannot load " + INTERNAL_CONFIGURATION + " file"); } } manager.addCache(WISDOM_KEY); cache = manager.getCache(WISDOM_KEY); registration = context.registerService(Cache.class, this, new Hashtable<String, Object>()); } finally { Thread.currentThread().setContextClassLoader(original); } }
Example #22
Source File: JGroupsCacheManagerPeerProviderFactory.java From unitime with Apache License 2.0 | 5 votes |
@Override public CacheManagerPeerProvider createCachePeerProvider(CacheManager cacheManager, Properties properties) { try { String configuration = JGroupsUtils.getConfigurationString(ApplicationProperty.HibernateClusterConfiguration.value()); JGroupsCacheManagerPeerProvider peerProvider = new JGroupsCacheManagerPeerProvider(cacheManager, configuration); peerProvider.setChannelName("UniTime:hibernate"); return peerProvider; } catch (Exception e) { Debug.error(e.getMessage(), e); return null; } }
Example #23
Source File: Output.java From red5-io with Apache License 2.0 | 5 votes |
private static CacheManager constructDefault() { CacheManager manager = CacheManager.getInstance(); manager.addCacheIfAbsent("org.red5.io.amf.Output.stringCache"); manager.addCacheIfAbsent("org.red5.io.amf.Output.getterCache"); manager.addCacheIfAbsent("org.red5.io.amf.Output.fieldCache"); manager.addCacheIfAbsent("org.red5.io.amf.Output.serializeCache"); return manager; }
Example #24
Source File: AliveTimerCacheConfig.java From c2mon with GNU Lesser General Public License v3.0 | 5 votes |
@Bean public EhCacheFactoryBean aliveTimerEhcache(CacheManager cacheManager) { EhCacheFactoryBean factory = new EhCacheFactoryBean(); factory.setCacheName("aliveTimerCache"); factory.setCacheManager(cacheManager); return factory; }
Example #25
Source File: EhcacheMap.java From concurrentlinkedhashmap with Apache License 2.0 | 5 votes |
public EhcacheMap(MemoryStoreEvictionPolicy evictionPolicy, CacheFactory builder) { CacheConfiguration config = new CacheConfiguration(DEFAULT_CACHE_NAME, builder.maximumCapacity); config.setMemoryStoreEvictionPolicyFromObject(evictionPolicy); CacheManager cacheManager = new CacheManager(); cache = new Cache(config); cache.setCacheManager(cacheManager); cache.initialise(); }
Example #26
Source File: DeviceClassCacheConfig.java From c2mon with GNU Lesser General Public License v3.0 | 5 votes |
@Bean public EhCacheFactoryBean deviceClassEhcache(CacheManager cacheManager) { EhCacheFactoryBean factory = new EhCacheFactoryBean(); factory.setCacheName("deviceClassCache"); factory.setCacheManager(cacheManager); return factory; }
Example #27
Source File: RoleDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
private Role getFromCache(String key) { logger.debug("IN"); String tenantId = this.getTenant(); Role role = null; if (tenantId != null) { // The tenant is set, so let's find it into the cache String cacheName = tenantId + DEFAULT_CACHE_SUFFIX; try { if (cacheManager == null) { cacheManager = CacheManager.create(); logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get."); logger.debug("OUT"); return null; } else { if (!cacheManager.cacheExists(cacheName)) { logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get."); logger.debug("OUT"); return null; } else { Element el = cacheManager.getCache(cacheName).get(key); if (el != null) { role = (Role) el.getValue(); } } } } catch (Throwable t) { throw new SpagoBIRuntimeException("Error while getting a Role cache item with key " + key + " for tenant " + tenantId, t); } } logger.debug("OUT"); return role; }
Example #28
Source File: LdaptiveResourceCRLFetcherTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void getCrlFromLdapWithNoCaching() throws Exception { for (int i = 0; i < 10; i++) { CacheManager.getInstance().removeAllCaches(); final Cache cache = new Cache("crlCache-1", 100, false, false, 20, 10); CacheManager.getInstance().addCache(cache); final CRLDistributionPointRevocationChecker checker = new CRLDistributionPointRevocationChecker(cache, fetcher); checker.setThrowOnFetchFailure(true); checker.setUnavailableCRLPolicy(new AllowRevocationPolicy()); final X509Certificate cert = CertUtils.readCertificate(new ClassPathResource("ldap-crl.crt")); checker.check(cert); } }
Example #29
Source File: EHCacheUtil.java From sanshanblog with Apache License 2.0 | 5 votes |
/** * 初始化缓存管理容器 * * @param path * ehcache.xml存放的路徑 */ public static CacheManager initCacheManager(String path) { try { if (cacheManager == null) cacheManager = CacheManager.create(path); } catch (Exception e) { e.printStackTrace(); } return cacheManager; }
Example #30
Source File: ClearPassControllerTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Before public void prep() { this.manager = CacheManager.create(); this.manager.addCache("cascache"); this.cache = this.manager.getCache("cascache"); this.map = new EhcacheBackedMap(this.cache); }