当前位置: 首页>>代码示例>>Java>>正文


Java CacheConfiguration.setMemoryStoreEvictionPolicy方法代码示例

本文整理汇总了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);
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:22,代码来源:ServletCache.java

示例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);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:21,代码来源:DaoSpringModuleConfig.java

示例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;
}
 
开发者ID:gleb619,项目名称:hotel_shop,代码行数:24,代码来源:CacheConfig.java

示例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);
}
 
开发者ID:yaohuiwu,项目名称:CAM,代码行数:23,代码来源:Caches.java

示例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);
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:15,代码来源:CachingConfiguration.java

示例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());
	}
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:51,代码来源:PersistQueue.java

示例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);
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:47,代码来源:CacheQueue.java

示例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);
}
 
开发者ID:jchampemont,项目名称:notedown,代码行数:13,代码来源:CachingConfiguration.java

示例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);
}
 
开发者ID:daedafusion,项目名称:knowledge,代码行数:13,代码来源:MemoryOnlyEhcache.java

示例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);
    }
 
开发者ID:gleb619,项目名称:hotel_shop,代码行数:36,代码来源:CacheConfig.java

示例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;
}
 
开发者ID:PinaeOS,项目名称:timon,代码行数:31,代码来源:EhCache.java

示例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);
}
 
开发者ID:yaohuiwu,项目名称:CAM,代码行数:39,代码来源:InnerCacheTest.java

示例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);
}
 
开发者ID:mjeanroy,项目名称:springmvc-uadetector,代码行数:12,代码来源:EhCacheParserConfiguration.java

示例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);
}
 
开发者ID:mjeanroy,项目名称:springmvc-uadetector,代码行数:11,代码来源:EhCacheCacheTest.java

示例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));
	}
}
 
开发者ID:Kyunghwa-Yoo,项目名称:StitchRTSP,代码行数:54,代码来源:EhCacheImpl.java


注:本文中的net.sf.ehcache.config.CacheConfiguration.setMemoryStoreEvictionPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。