本文整理汇总了Java中net.sf.ehcache.config.CacheConfiguration.setMaxEntriesLocalHeap方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfiguration.setMaxEntriesLocalHeap方法的具体用法?Java CacheConfiguration.setMaxEntriesLocalHeap怎么用?Java CacheConfiguration.setMaxEntriesLocalHeap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.config.CacheConfiguration
的用法示例。
在下文中一共展示了CacheConfiguration.setMaxEntriesLocalHeap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCachePool
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@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);
}
}
示例2: createCachePool
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@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);
}
}
示例3: ServletCache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
private ServletCache(String name, int type) {
this.type = type;
Configuration managerConfig = new Configuration();
CacheConfiguration mqCf = new CacheConfiguration(name, CacheConfig
.getConfig().getMaxElementsInMemory());
mqCf.setEternal(true);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(CacheConfig.getConfig().getDiskStorePath());
managerConfig.addDiskStore(dsCf);
mqCf.setMaxElementsOnDisk(0);
mqCf.setMaxEntriesLocalHeap(CacheConfig.getConfig()
.getMaxElementsInMemory());
mqCf.persistence(new PersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));
mqCf.setTransactionalMode("OFF");
mqCf.setMemoryStoreEvictionPolicy(CacheConfig.getConfig()
.getMemoryStoreEvictionPolicy());
managerConfig.addCache(mqCf);
cacheManager = new CacheManager(managerConfig);
cache = cacheManager.getCache(name);
}
示例4: loadCache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* Load cache.
*
* @param name the name
* @return the cache configuration
*/
private CacheConfiguration loadCache(String name) {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(10000);
cacheConfiguration.setMaxEntriesLocalDisk(1000000);
if (debug) {
cacheConfiguration.setTimeToIdleSeconds(1);
cacheConfiguration.setTimeToLiveSeconds(2);
}
else {
cacheConfiguration.setTimeToIdleSeconds(10);
cacheConfiguration.setTimeToLiveSeconds(20);
}
cacheConfiguration.setName(name);
return cacheConfiguration;
}
示例5: createMemCache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
public static Cache createMemCache(String name , long maxEntriesLocalHeap, long timeToLiveSeconds,
long timeToIdleSeconds){
CacheConfiguration config = new CacheConfiguration();
config.setName(name);
config.setEternal(false);
config.setMaxEntriesLocalHeap(maxEntriesLocalHeap);
config.setTimeToLiveSeconds(timeToLiveSeconds);
config.setTimeToIdleSeconds(timeToIdleSeconds);
config.setCopyOnRead(false);
config.setCopyOnWrite(true);
config.setMemoryStoreEvictionPolicy("LRU");
CopyStrategyConfiguration copyConfig = new CopyStrategyConfiguration();
copyConfig.setClass("org.cam.core.cache.CloneCopyStrategy");
config.addCopyStrategy(copyConfig);
PersistenceConfiguration persistConfig = new PersistenceConfiguration();
persistConfig.setStrategy("NONE");
config.addPersistence(persistConfig);
return new Cache(config);
}
示例6: ehCacheManager
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Bean(destroyMethod="shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("categoryCache");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(1000);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
//config.addCache(cacheConfiguration);
config.defaultCache(cacheConfiguration);
return net.sf.ehcache.CacheManager.newInstance(config);
}
示例7: PersistQueue
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* 构造函数
*
* @param block
* --是否为阻塞队列,true是阻塞队列,false是非阻塞队列
* @param cacheLength
* --内存中队列长度,值>0;
* @param persistDirPath
* --持久数据落地目录(<b>注意:一个队列对应一个目录路径,多个队列共享一个目录路径,是不允许的,会出现数据不一致的情况!
* < /b>)
*/
public PersistQueue(final boolean block, final int cacheLength,
final String persistDirPath) {
if (cacheLength < 0) {
throw new AppRuntimeException("cacheLength must >0!");
}
if (block) {
this.tmpQueue = new BlockQueue();
} else {
this.tmpQueue = new NoBlockConcurrentQueue();
}
psKeys = new ConcurrentLinkedQueue<Long>();
hcName = "pq_" + persistDirPath.hashCode();
Configuration managerConfig = new Configuration();
CacheConfiguration mqCf = new CacheConfiguration(hcName, cacheLength);
mqCf.setEternal(true);
// mqCf.setDiskStorePath(persistDirPath);
mqCf.setMaxElementsOnDisk(0);
mqCf.setTransactionalMode("OFF");
mqCf.setMemoryStoreEvictionPolicy("LFU");
// mqCf.setDiskPersistent(true);
// mqCf.setMaxElementsInMemory(cacheLength);
mqCf.setMaxEntriesLocalHeap(cacheLength);
// mqCf.setOverflowToDisk(true);
mqCf.persistence(new PersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.LOCALRESTARTABLE));
managerConfig.addCache(mqCf);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(persistDirPath);
managerConfig.addDiskStore(dsCf);
cacheManager = new CacheManager(managerConfig);
cache = cacheManager.getCache(hcName);
Element e = cache.get(hcName);
if (null == e) {
count = new AtomicLong(0);
} else {
Long cv = (Long) e.getObjectValue();
count = new AtomicLong(cv.longValue());
}
}
示例8: CacheQueue
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* 构造函数
*
* @param block
* --是否为阻塞队列,true是阻塞队列,false是非阻塞队列
* @param cacheLength
* --内存中队列长度,值>0;
* @param persistDirPath
* --数据落地目录(<b>注意:一个队列对应一个目录路径,多个队列共享一个目录路径,是不允许的,会出现数据不一致的情况! <
* /b>)
*/
public CacheQueue(final boolean block, final int cacheLength,
final String persistDirPath) {
if (cacheLength < 0) {
throw new AppRuntimeException("cacheLength must >0!");
}
if (block) {
this.tmpQueue = new BlockQueue();
} else {
this.tmpQueue = new NoBlockConcurrentQueue();
}
psKeys = new ConcurrentLinkedQueue<Long>();
hcName = "cq-" + persistDirPath.hashCode();
Configuration managerConfig = new Configuration();
CacheConfiguration mqCf = new CacheConfiguration(hcName, cacheLength);
mqCf.setEternal(true);
// mqCf.setDiskStorePath(persistDirPath);
mqCf.setMaxElementsOnDisk(0);
mqCf.setTransactionalMode("OFF");
mqCf.setMemoryStoreEvictionPolicy("LFU");
// mqCf.setDiskPersistent(true);
// mqCf.setMaxElementsInMemory(cacheLength);
mqCf.setMaxEntriesLocalHeap(cacheLength);
// mqCf.setOverflowToDisk(true);
mqCf.persistence(new PersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));
managerConfig.addCache(mqCf);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(persistDirPath);
managerConfig.addDiskStore(dsCf);
managerConfig.setName(hcName);
// cacheManager = new CacheManager(managerConfig);
cacheManager = CacheManager.newInstance(managerConfig);
cache = cacheManager.getCache(hcName);
count = new AtomicLong(0);
}
示例9: ehCacheManager
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Bean(destroyMethod = "shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("notedown");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(1000);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(cacheConfiguration);
return net.sf.ehcache.CacheManager.newInstance(config);
}
示例10: ehCacheManager
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* Eh cache manager.
*
* @return the net.sf.ehcache. cache manager
*/
@SuppressWarnings("deprecation")
@Bean(destroyMethod="shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(1000);
cacheConfiguration.setEternal(false);
cacheConfiguration.setOverflowToDisk(true);
cacheConfiguration.setMaxElementsInMemory(1000);
cacheConfiguration.setMaxElementsOnDisk(10000);
// cacheConfiguration.setDiskPersistent(false);
// cacheConfiguration.setStatistics(false);
cacheConfiguration.setTimeToIdleSeconds(300);
cacheConfiguration.setTimeToLiveSeconds(600);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
diskStoreConfiguration.setPath(System.getProperty("java.io.tmpdir"));
config.diskStore(diskStoreConfiguration);
config.setDynamicConfig(true);
config.setMonitoring("autodetect");
config.setUpdateCheck(false);
config.defaultCache(cacheConfiguration);
CacheSettings.Items.list.parallelStream().forEach(it -> {
config.addCache(loadCache(it));
});
return net.sf.ehcache.CacheManager.newInstance(config);
}
示例11: EhCache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
public EhCache(String name, EhCacheConfiguration config) {
super(name);
String configUrl = config.getConfigUrl();
if (configUrl == null) {
CacheConfiguration cacheConfig = new CacheConfiguration();
cacheConfig.setName(name);
cacheConfig.setMemoryStoreEvictionPolicy(config.getEvictionPolicy());
cacheConfig.setMaxEntriesLocalHeap(config.getMaxHeapSize());
if (config.getMaxMemorySize() > 0) {
cacheConfig.setMaxBytesLocalHeap(MemoryUnit.BYTES.toBytes(config.getMaxMemorySize()));
}
if (config.getExpire() > 0) {
cacheConfig.timeToLiveSeconds(config.getExpire());
}
if (EhCache.Manager == null) {
EhCache.Manager = new CacheManager();
}
this.cache = new Cache(cacheConfig);
EhCache.Manager.addCache(this.cache);
} else {
EhCache.Manager = CacheManager.newInstance(configUrl);
this.cache = EhCache.Manager.getCache(name);
}
this.config = config;
}
示例12: BlockingCacheFactory
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
public BlockingCacheFactory(int timeToLiveSeconds, int maxEntriesLocalHeap) {
Configuration cfg = new Configuration();
CacheConfiguration.CacheDecoratorFactoryConfiguration cdfc =
new CacheConfiguration.CacheDecoratorFactoryConfiguration();
cdfc.setClass(BlockingCacheDecoratorFactory.class.getName());
CacheConfiguration defaultCacheCfg = new CacheConfiguration();
defaultCacheCfg.addCacheDecoratorFactory(cdfc);
defaultCacheCfg.setTimeToLiveSeconds(timeToLiveSeconds);
defaultCacheCfg.setMaxEntriesLocalHeap(maxEntriesLocalHeap);
cfg.addDefaultCache(defaultCacheCfg);
manager = CacheManager.create(cfg);
}
示例13: cacheConfiguration
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
private CacheConfiguration cacheConfiguration(String name) {
CacheConfiguration cc = new CacheConfiguration();
cc.setMaxEntriesLocalHeap(size);
cc.setOverflowToDisk(false);
cc.setEternal(true);
cc.setName(DocumentLoaderCachingProxy.class.getCanonicalName() + "." + name);
return cc;
}
示例14: testCreateCacheManual
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Test
public void testCreateCacheManual() throws Exception {
CacheConfiguration config = new CacheConfiguration();
config.setName("queryListCache");
config.setEternal(false);
config.setMaxEntriesLocalHeap(1000);
config.setTimeToLiveSeconds(3600);
config.setTimeToIdleSeconds(3600);
config.setCopyOnRead(false);
config.setCopyOnWrite(true);
config.setMemoryStoreEvictionPolicy("LRU");
CopyStrategyConfiguration copyConfig = new CopyStrategyConfiguration();
copyConfig.setClass("org.cam.core.cache.CloneCopyStrategy");
config.addCopyStrategy(copyConfig);
PersistenceConfiguration persistConfig = new PersistenceConfiguration();
persistConfig.setStrategy("NONE");
config.addPersistence(persistConfig);
Cache cache = new Cache(config);
CacheManager manager = CacheManager.getInstance();
manager.addCache(cache);
StringSet mySet = new StringSet(Sets.newSet("1","2"));
cache.put(new Element("mySet",mySet));
Element e = cache.get("mySet");
Assert.assertNotNull(e);
Assert.assertNotNull(e.getObjectValue());
StringSet stringSet = (StringSet) e.getObjectValue();
Assert.assertEquals(2 , stringSet.getIdSet().size());
System.out.println(stringSet);
}
示例15: cache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
protected UADetectorCache cache(UserAgentStringParser parser) {
CacheManager cacheManager = CacheManager.getInstance();
Cache ehCache = cacheManager.getCache("uadetector");
CacheConfiguration configuration = ehCache.getCacheConfiguration();
configuration.setMemoryStoreEvictionPolicy("LRU");
configuration.setMaxEntriesLocalHeap(getMaximumSize());
configuration.setTimeToLiveSeconds(getTimeToLiveInSeconds());
return new EhCacheCache(ehCache, parser);
}