本文整理了Java中net.sf.ehcache.config.Configuration
类的一些代码示例,展示了Configuration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration
类的具体详情如下:
包路径:net.sf.ehcache.config.Configuration
类名称:Configuration
[英]A bean, used by BeanUtils, to set configuration from an XML configuration file.
[中]BeanUtils使用的bean,用于从XML配置文件设置配置。
代码示例来源:origin: apache/kylin
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
Configuration conf = new Configuration();
conf.setMaxBytesLocalHeap("100M");
CacheManager cacheManager = CacheManager.create(conf);
new Cache(new CacheConfiguration("test", 0).//
memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).//
eternal(false).//
timeToIdleSeconds(86400).//
persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE)));
cacheManager.addCache(testCache);
testCache.put(new Element("1", blob));
System.out.println(testCache.get("1") == null);
System.out.println(testCache.getSize());
System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
cacheManager.shutdown();
代码示例来源:origin: spring-projects/spring-framework
EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
if (this.cacheManagerName != null) {
configuration.setName(this.cacheManagerName);
this.cacheManager = CacheManager.create(configuration);
this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
if (this.cacheManager == null) {
this.cacheManager = new CacheManager(configuration);
代码示例来源:origin: hibernate/hibernate-orm
final Configuration config = ConfigurationFactory.parseConfiguration( url );
if ( config.getDefaultCacheConfiguration() != null
&& config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
setupHibernateTimeoutBehavior(
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.getNonstopConfiguration()
);
for ( CacheConfiguration cacheConfig : config.getCacheConfigurations().values() ) {
if ( cacheConfig.isTerracottaClustered() ) {
setupHibernateTimeoutBehavior( cacheConfig.getTerracottaConfiguration().getNonstopConfiguration() );
代码示例来源:origin: gocd/gocd
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);
}
}
代码示例来源:origin: gocd/gocd
@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);
}
代码示例来源:origin: hibernate/hibernate-orm
static void setCacheManagerNameIfNeeded(SessionFactoryOptions settings, Configuration configuration, Map properties) {
overwriteCacheManagerIfConfigured( configuration, properties );
if (configuration.getName() == null) {
String sessionFactoryName = settings.getSessionFactoryName();
if (sessionFactoryName != null) {
configuration.setName( sessionFactoryName );
}
else {
configuration.setName( "Hibernate " + settings.getUuid() );
}
}
}
代码示例来源:origin: net.sf.ehcache/ehcache
addAttribute(new SimpleNodeAttribute("name", configuration.getName()).optional(true));
addAttribute(new SimpleNodeAttribute("monitoring", configuration.getMonitoring()).optional(true).defaultValue(
Configuration.DEFAULT_MONITORING.name().toLowerCase()));
addAttribute(new SimpleNodeAttribute("dynamicConfig", configuration.getDynamicConfig()).optional(true).defaultValue(
String.valueOf(Configuration.DEFAULT_DYNAMIC_CONFIG)));
addAttribute(new SimpleNodeAttribute("defaultTransactionTimeoutInSeconds", configuration.getDefaultTransactionTimeoutInSeconds())
.optional(true).defaultValue(String.valueOf(Configuration.DEFAULT_TRANSACTION_TIMEOUT)));
testAddMaxBytesLocalHeapAttribute();
testAddCacheManagerPeerListenerFactoryElement();
addChildElement(new DefaultCacheConfigurationElement(this, configuration, configuration.getDefaultCacheConfiguration()));
for (String cacheName : cacheManager.getCacheNames()) {
boolean decoratedCache = false;
Ehcache cache = cacheManager.getCache(cacheName);
if (cache == null) {
cache = cacheManager.getEhcache(cacheName);
decoratedCache = true;
CacheConfiguration config = decoratedCache ? cache.getCacheConfiguration().clone().name(cacheName) : cache.getCacheConfiguration();
addChildElement(new CacheConfigurationElement(this, configuration, config));
for (CacheConfiguration cacheConfiguration : configuration.getCacheConfigurations().values()) {
addChildElement(new CacheConfigurationElement(this, configuration, cacheConfiguration));
代码示例来源:origin: nschlimm/playground
public static void main(String[] args) throws CacheException, FileNotFoundException {
CacheManager mgr = CacheManager.newInstance();
System.out.println(mgr.getConfiguration().getCacheConfigurations().toString());
Cache cache = mgr.getCache("sampleCache1");
cache.put(new Element("Frank", "Groer Junge!"));
System.out.println(cache.get("Frank"));
mgr.shutdown();
}
}
代码示例来源:origin: actiontech/dble
@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);
}
}
代码示例来源:origin: io.github.hengyunabc/mybatis-ehcache-spring
@Override
public Cache getCache(String id) {
if (id == null) {
throw new IllegalArgumentException("Cache instances require an ID");
}
if (!cacheManager.cacheExists(id)) {
CacheConfiguration temp = null;
if (cacheConfiguration != null) {
temp = cacheConfiguration.clone();
} else {
// based on defaultCache
temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
}
temp.setName(id);
net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp);
cacheManager.addCache(cache);
}
return new EhcacheCache(id, cacheManager.getEhcache(id));
}
代码示例来源:origin: org.red5/red5-io
CacheManager cm = CacheManager.getInstance();
Configuration configuration = new Configuration();
conf.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
conf.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
if (null == cache) {
defaultCacheName = conf.getName();
configuration.addDefaultCache(conf);
} else {
configuration.addCache(conf);
cache.initialise();
cache.bootstrap();
nonDefaultCache.initialise();
nonDefaultCache.bootstrap();
nonDefaultCache = cm.getCache(defaultCacheName);
代码示例来源:origin: org.sakaiproject.kernel/sakai-kernel-impl
buf.append("\n\n");
String[] allCacheNames = cacheManager.getCacheNames();
Arrays.sort(allCacheNames);
ArrayList<Ehcache> caches = new ArrayList<Ehcache>(allCacheNames.length);
for (String cacheName : allCacheNames) {
Ehcache cache = cacheManager.getCache(cacheName);
caches.add(cache);
buf.append(cache.toString());
buf.append("\n");
CacheConfiguration defaults = cacheManager.getConfiguration().getDefaultCacheConfiguration();
long maxEntriesDefault = defaults.getMaxEntriesLocalHeap();
long ttlSecsDefault = defaults.getTimeToLiveSeconds();
long ttiSecsDefault = defaults.getTimeToIdleSeconds();
boolean eternalDefault = defaults.isEternal();
buf.append("# DEFAULTS: ").append(maxKey).append("=").append(maxEntriesDefault).append(",").append(ttlKey).append("=").append(ttlSecsDefault).append(",").append(ttiKey).append("=").append(ttiSecsDefault).append(",").append(eteKey).append("=").append(eternalDefault).append("\n");
long maxEntries = cache.getCacheConfiguration().getMaxEntriesLocalHeap();
long ttlSecs = cache.getCacheConfiguration().getTimeToLiveSeconds();
long ttiSecs = cache.getCacheConfiguration().getTimeToIdleSeconds();
boolean eternal = cache.getCacheConfiguration().isEternal();
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-ehcache
/**
* Gets the cache with the given name from Ehache.
* <p>
* If no cache with that name exists, one will be created and registered, using the configuration from the cache
* with the given template name.
*/
private static net.sf.ehcache.Cache getCache(CacheManager embeddedCacheManager, String cacheName, String templateName) {
net.sf.ehcache.Cache cache = embeddedCacheManager.getCache( cacheName );
if ( cache == null ) {
CacheConfiguration configuration = embeddedCacheManager.getConfiguration().getCacheConfigurations().get( templateName ).clone();
configuration.setName( cacheName );
cache = new net.sf.ehcache.Cache( configuration );
embeddedCacheManager.addCache( cache );
}
return cache;
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: net.oschina.j2cache/j2cache-core
@Override
public EhCache buildCache(String region, long timeToLiveInSeconds, CacheExpiredListener listener) {
EhCache ehcache = caches.computeIfAbsent(region, v -> {
//配置缓存
CacheConfiguration cfg = manager.getConfiguration().getDefaultCacheConfiguration().clone();
cfg.setName(region);
if(timeToLiveInSeconds > 0) {
cfg.setTimeToLiveSeconds(timeToLiveInSeconds);
cfg.setTimeToIdleSeconds(timeToLiveInSeconds);
}
net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg);
manager.addCache(cache);
log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds);
return new EhCache(cache, listener);
});
if (ehcache.ttl() != timeToLiveInSeconds)
throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds));
return ehcache;
}
代码示例来源:origin: org.ujmp/ujmp-ehcache
private CacheManager getCacheManager() {
if (manager == null) {
Configuration config = new Configuration();
CacheConfiguration cacheconfig = new CacheConfiguration(getName(), maxElementsInMemory);
cacheconfig.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
cacheconfig.setDiskPersistent(diskPersistent);
cacheconfig.setEternal(eternal);
cacheconfig.setMaxElementsOnDisk(maxElementsOnDisk);
cacheconfig.setMemoryStoreEvictionPolicyFromObject(memoryStoreEvictionPolicy);
cacheconfig.setOverflowToDisk(overflowToDisk);
cacheconfig.setTimeToIdleSeconds(timeToIdleSeconds);
cacheconfig.setTimeToLiveSeconds(timeToLiveSeconds);
DiskStoreConfiguration diskStoreConfigurationParameter = new DiskStoreConfiguration();
diskStoreConfigurationParameter.setPath(getPath().getAbsolutePath());
config.addDiskStore(diskStoreConfigurationParameter);
config.setDefaultCacheConfiguration(cacheconfig);
manager = new CacheManager(config);
}
return manager;
}
代码示例来源:origin: openmrs/openmrs-core
@Override
public CacheManager getObject() {
CacheManager cacheManager = super.getObject();
Map<String, CacheConfiguration> cacheConfig = cacheManager.getConfiguration().getCacheConfigurations();
List<CacheConfiguration> cacheConfigurations = CachePropertiesUtil.getCacheConfigurations();
cacheConfigurations.stream()
.filter(cc ->
cacheConfig.get(cc.getName()) == null)
.forEach(cc ->
cacheManager.addCache(new Cache(cc)));
return cacheManager;
}
}
代码示例来源:origin: com.atlassian.cache/atlassian-cache-ehcache
CacheConfiguration config = ehMgr.getConfiguration().getDefaultCacheConfiguration().clone()
.name(name)
.statistics(statisticsEnabled)
.persistence(PERSISTENCE_CONFIGURATION);
Ehcache cache = new net.sf.ehcache.Cache(config);
if (selfLoading)
return ehMgr.addCacheIfAbsent(cache);
代码示例来源:origin: net.sf.ehcache/ehcache
/**
* Creates decorated ehcaches for the cache, if any configured in ehcache.xml
*
* @param cache the cache
* @return List of the decorated ehcaches, if any configured in ehcache.xml otherwise returns empty list
*/
public List<Ehcache> createCacheDecorators(Ehcache cache) {
CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
if (cacheConfiguration == null) {
return createDefaultCacheDecorators(cache, configuration.getDefaultCacheConfiguration(), loader);
}
List<CacheDecoratorFactoryConfiguration> cacheDecoratorConfigurations = cacheConfiguration.getCacheDecoratorConfigurations();
if (cacheDecoratorConfigurations == null || cacheDecoratorConfigurations.size() == 0) {
LOG.debug("CacheDecoratorFactory not configured. Skipping for '" + cache.getName() + "'.");
return createDefaultCacheDecorators(cache, configuration.getDefaultCacheConfiguration(), loader);
}
List<Ehcache> result = new ArrayList<Ehcache>();
for (CacheDecoratorFactoryConfiguration factoryConfiguration : cacheDecoratorConfigurations) {
Ehcache decoratedCache = createDecoratedCache(cache, factoryConfiguration, false, loader);
if (decoratedCache != null) {
result.add(decoratedCache);
}
}
for (Ehcache defaultDecoratedCache : createDefaultCacheDecorators(cache, configuration.getDefaultCacheConfiguration(), loader)) {
result.add(defaultDecoratedCache);
}
return result;
}
代码示例来源:origin: gustavoorsi/e-learning
@Bean(destroyMethod = "shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("restApiAuthTokenCache");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(0); // 0 = MAX
cacheConfiguration.setTimeToLiveSeconds(14400); // 4 hours.
cacheConfiguration.setEternal(false);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(cacheConfiguration);
return net.sf.ehcache.CacheManager.newInstance(config);
}
内容来源于网络,如有侵权,请联系作者删除!