本文整理汇总了Java中net.sf.ehcache.config.CacheConfiguration.setMemoryStoreEvictionPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfiguration.setMemoryStoreEvictionPolicy方法的具体用法?Java CacheConfiguration.setMemoryStoreEvictionPolicy怎么用?Java CacheConfiguration.setMemoryStoreEvictionPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.config.CacheConfiguration
的用法示例。
在下文中一共展示了CacheConfiguration.setMemoryStoreEvictionPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: ehCacheManager
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* Gets an EH Cache manager.
*
* @return the EH Cache manager.
*/
@Bean(destroyMethod = "shutdown")
public net.sf.ehcache.CacheManager ehCacheManager()
{
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName(HERD_CACHE_NAME);
cacheConfiguration.setTimeToLiveSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_LIVE_SECONDS, Long.class));
cacheConfiguration.setTimeToIdleSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_IDLE_SECONDS, Long.class));
cacheConfiguration.setMaxElementsInMemory(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MAX_ELEMENTS_IN_MEMORY, Integer.class));
cacheConfiguration.setMemoryStoreEvictionPolicy(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MEMORY_STORE_EVICTION_POLICY));
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(cacheConfiguration);
return net.sf.ehcache.CacheManager.create(config);
}
示例3: 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;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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());
}
}
示例7: 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);
}
示例8: 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);
}
示例9: MemoryOnlyEhcache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
public MemoryOnlyEhcache(String size, String namePrefix)
{
CacheConfiguration config = new CacheConfiguration();
config.setMaxBytesLocalHeap(size);
config.persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE));
config.setMemoryStoreEvictionPolicy("LRU");
config.eternal(true);
config.setName(String.format("%s-%s", namePrefix, UUID.randomUUID().toString()));
cache = new net.sf.ehcache.Cache(config);
CacheManager.getInstance().addCache(cache);
}
示例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: 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);
}
示例13: 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);
}
示例14: setUp
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Before
public void setUp() {
cacheManager.addCache("uadetector");
ehCache = cacheManager.getCache("uadetector");
CacheConfiguration configuration = ehCache.getCacheConfiguration();
configuration.setMemoryStoreEvictionPolicy("LRU");
configuration.setMaxEntriesLocalHeap(100);
configuration.setTimeToLiveSeconds(3);
}
示例15: init
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "unused" })
public void init() {
log.info("Loading ehcache");
// log.debug("Appcontext: " + applicationContext.toString());
try {
// instance the manager
CacheManager cm = CacheManager.getInstance();
// Use the Configuration to create our caches
Configuration configuration = new Configuration();
//set initial default cache name
String defaultCacheName = Cache.DEFAULT_CACHE_NAME;
//add the configs to a configuration
for (CacheConfiguration conf : configs) {
//set disk expiry
conf.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
//set eviction policy
conf.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
if (null == cache) {
//get first cache name and use as default
defaultCacheName = conf.getName();
configuration.addDefaultCache(conf);
} else {
configuration.addCache(conf);
}
}
//instance the helper
ConfigurationHelper helper = new ConfigurationHelper(cm, configuration);
//create the default cache
cache = helper.createDefaultCache();
//init the default
cache.initialise();
cache.bootstrap();
//create the un-init'd caches
Set<Cache> caches = helper.createCaches();
if (log.isDebugEnabled()) {
log.debug("Number of caches: " + caches.size() + " Default cache: " + (cache != null ? 1 : 0));
}
for (Cache nonDefaultCache : caches) {
nonDefaultCache.initialise();
nonDefaultCache.bootstrap();
//set first cache to be main local member
if (null == nonDefaultCache) {
log.debug("Default cache name: {}", defaultCacheName);
nonDefaultCache = cm.getCache(defaultCacheName);
}
}
} catch (Exception e) {
log.warn("Error on cache init", e);
}
if (log.isDebugEnabled()) {
log.debug("Cache is null? {}", (null == cache));
}
}