當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheConfiguration.setEternal方法代碼示例

本文整理匯總了Java中net.sf.ehcache.config.CacheConfiguration.setEternal方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheConfiguration.setEternal方法的具體用法?Java CacheConfiguration.setEternal怎麽用?Java CacheConfiguration.setEternal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sf.ehcache.config.CacheConfiguration的用法示例。


在下文中一共展示了CacheConfiguration.setEternal方法的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: getCacheManager

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
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;
}
 
開發者ID:ujmp,項目名稱:universal-java-matrix-package,代碼行數:22,代碼來源:EhcacheMap.java

示例3: getCacheConfiguration

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
/**
 * Read cache config from the file caches.dat
 *
 * @param strCacheName
 *            The cache name
 * @return The config
 */
private CacheConfiguration getCacheConfiguration( String strCacheName )
{
    CacheConfiguration config = new CacheConfiguration( );
    config.setName( strCacheName );
    config.setMaxElementsInMemory( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS, _nDefaultMaxElementsInMemory ) );
    config.setEternal( getBooleanProperty( strCacheName, PROPERTY_ETERNAL, _bDefaultEternal ) );
    config.setTimeToIdleSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_IDLE, _lDefaultTimeToIdle ) );
    config.setTimeToLiveSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_LIVE, _lDefaultTimeToLive ) );
    config.setOverflowToDisk( getBooleanProperty( strCacheName, PROPERTY_OVERFLOW_TO_DISK, _bDefaultOverflowToDisk ) );
    config.setDiskPersistent( getBooleanProperty( strCacheName, PROPERTY_DISK_PERSISTENT, _bDefaultDiskPersistent ) );
    config.setDiskExpiryThreadIntervalSeconds( getLongProperty( strCacheName, PROPERTY_DISK_EXPIRY, _lDefaultDiskExpiry ) );
    config.setMaxElementsOnDisk( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS_DISK, _nDefaultMaxElementsOnDisk ) );
    config.setStatistics( getBooleanProperty( strCacheName, PROPERTY_STATISTICS, _bDefaultStatistics ) );

    return config;
}
 
開發者ID:lutece-platform,項目名稱:lutece-core,代碼行數:24,代碼來源:CacheService.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: add

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
public void add(Query query) {
    String name = query.getQid().getId();
    if (!this.manager.cacheExists(name) && query.isCacheable()) {
        
        CacheConfiguration config = defaultConfig.clone();
        config.setName(name);
        config.setEternal(query.isEternal());
        config.setTimeToLiveSeconds(query.getCacheTime());
        
        Cache c = new Cache(config);
        this.manager.addCache(c);
        
        if (log.isDebugEnabled()) {
            log.debug(String.format("Cache %s created: eternal = %s, cacheTime = %d", 
                    c.getName(), query.isEternal(), query.getCacheTime()));
        }
        
    }
}
 
開發者ID:valdasraps,項目名稱:resthub,代碼行數:20,代碼來源:CacheFactory.java

示例6: createCacheConfiguration

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
protected CacheConfiguration createCacheConfiguration(int _maxElements) {
  MemoryStoreEvictionPolicy _policy = MemoryStoreEvictionPolicy.LRU;
  switch (algorithm) {
    case CLOCK: _policy = MemoryStoreEvictionPolicy.CLOCK; break;
  }
  CacheConfiguration c = new CacheConfiguration(CACHE_NAME, _maxElements)
    .memoryStoreEvictionPolicy(_policy)
    .eternal(true)
    .diskExpiryThreadIntervalSeconds(0)
    .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE));
  if (withExpiry) {
    c.setEternal(false);
    c.setTimeToLiveSeconds(5 * 60);
  }
  return c;
}
 
開發者ID:cache2k,項目名稱:cache2k-benchmark,代碼行數:17,代碼來源:EhCache2Factory.java

示例7: createCache

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
protected void createCache(String name, int expirationTime) {
		synchronized (this.getClass()) {
			cacheManager.addCache(name);

			Ehcache cache = cacheManager.getEhcache(name);
			CacheConfiguration config = cache.getCacheConfiguration();
			config.setEternal(false);
			config.setTimeToLiveSeconds(expirationTime);
//		    config.setTimeToIdleSeconds(60);
//		    config.setMaxElementsInMemory(10000);
//		    config.setMaxElementsOnDisk(1000000);
		    
			BlockingCache blockingCache = new BlockingCache(cache);
			cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache);
		}
	}
 
開發者ID:nextreports,項目名稱:nextreports-server,代碼行數:17,代碼來源:EhCacheFactory.java

示例8: afterPropertiesSet

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void afterPropertiesSet() throws Exception {
    Cache.ID = key + "." + Dates.newDateStringOfFormatDateTimeSSSNoneSpace();
    Cache.HOST = Utils.getLocalHostIP();
    Cache.CACHE_STORE = key + spliter + "cache" + spliter + "store";
    Cache.CACHE_STORE_SYNC = Cache.CACHE_STORE + spliter + "sync";
    if (this.localEnabled) {
        Configuration configuration = new Configuration();
        configuration.setName(Cache.ID);
        configuration.setMaxBytesLocalHeap(localMaxBytesLocalHeap);
        configuration.setMaxBytesLocalDisk(localMaxBytesLocalDisk);
        // DiskStore
        // 每次啟動設置新的文件地址,以避免重啟期間一級緩存未同步,以及單機多應用啟動造成EhcacheManager重複的問題.
        DiskStoreConfiguration dsc = new DiskStoreConfiguration();
        dsc.setPath(localStoreLocation + Cache.ID);
        configuration.diskStore(dsc);
        // DefaultCache
        CacheConfiguration defaultCacheConfiguration = new CacheConfiguration();
        defaultCacheConfiguration.setEternal(false);
        defaultCacheConfiguration.setOverflowToDisk(true);
        defaultCacheConfiguration.setDiskPersistent(false);
        defaultCacheConfiguration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU);
        defaultCacheConfiguration.setDiskExpiryThreadIntervalSeconds(localDiskExpiryThreadIntervalSeconds);
        // 默認false,使用引用.設置為true,避免外部代碼修改了緩存對象.造成EhCache的緩存對象也隨之改變
        // 但是設置為true後,將引起element的tti不自動刷新.如果直接新建element去覆蓋原值.則本地ttl和遠程ttl會產生一定的誤差.
        // 因此,使用時放棄手動覆蓋方式刷新本地tti,當本地tti過期後,自動從Redis中再獲取即可.
        defaultCacheConfiguration.copyOnRead(true);
        defaultCacheConfiguration.copyOnWrite(true);
        defaultCacheConfiguration.setTimeToIdleSeconds(localTimeToIdleSeconds);
        defaultCacheConfiguration.setTimeToLiveSeconds(localTimeToLiveSeconds);
        configuration.setDefaultCacheConfiguration(defaultCacheConfiguration);
        configuration.setDynamicConfig(false);
        configuration.setUpdateCheck(false);
        this.cacheManager = new CacheManager(configuration);
        this.cacheSync = new RedisPubSubSync(this);// 使用Redis Topic發送訂閱緩存變更消息
    }
}
 
開發者ID:yrain,項目名稱:smart-cache,代碼行數:39,代碼來源:CacheTemplate.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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;
}
 
開發者ID:imCodePartnerAB,項目名稱:imcms,代碼行數:11,代碼來源:DocumentLoaderCachingProxy.java

示例13: 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

示例14: overrideCacheConfiguration

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
protected void overrideCacheConfiguration(Properties properties, CacheConfiguration cacheConfig, String cacheName) {
	String cachePrefix = NET_SF_EHCACHE_REGION_PREFIX + cacheName + ".";

	if(properties.get(cachePrefix + "maxElementsInMemory") != null) {
		int maxElementsInMemory = Integer.parseInt((String)properties.get(cachePrefix + "maxElementsInMemory"));
		cacheConfig.setMaxElementsInMemory(maxElementsInMemory);
	}

	if(properties.get(cachePrefix + "eternal") != null) {
		boolean eternal = Boolean.parseBoolean((String)properties.get(cachePrefix + "eternal"));
		cacheConfig.setEternal(eternal);
	}

	if(properties.get(cachePrefix + "timeToIdleSeconds") != null) {
		long timeToIdleSeconds = Long.parseLong((String)properties.get(cachePrefix + "timeToIdleSeconds"));
		cacheConfig.setTimeToIdleSeconds(timeToIdleSeconds);
	}

	if(properties.get(cachePrefix + "timeToLiveSeconds") != null) {
		long timeToLiveSeconds = Long.parseLong((String)properties.get(cachePrefix + "timeToLiveSeconds"));
		cacheConfig.setTimeToLiveSeconds(timeToLiveSeconds);
	}

	if(properties.get(cachePrefix + "overflowToDisk") != null) {
		boolean overflowToDisk = Boolean.parseBoolean((String)properties.get(cachePrefix + "overflowToDisk"));
		cacheConfig.setOverflowToDisk(overflowToDisk);
	}

	if(properties.get(cachePrefix + "maxElementsOnDisk") != null){
		int maxElementsOnDisk = Integer.parseInt((String)properties.get(cachePrefix + "maxElementsOnDisk"));
		cacheConfig.setMaxElementsOnDisk(maxElementsOnDisk);
	}

	if(properties.get(cachePrefix + "diskPersistent") != null){
		boolean diskPersistent = Boolean.parseBoolean((String)properties.get(cachePrefix + "diskPersistent"));
		cacheConfig.setDiskPersistent(diskPersistent);
	}

	if(properties.get(cachePrefix + "diskExpiryThreadIntervalSeconds") != null) {
		long diskExpiryThreadIntervalSeconds = Long.parseLong((String)properties.get(cachePrefix + "diskExpiryThreadIntervalSeconds"));
		cacheConfig.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
	}

	if(properties.get(cachePrefix + "diskExpiryThreadIntervalSeconds") != null) {
		String memoryStoreEvictionPolicy = (String) properties.get(cachePrefix + "memoryStoreEvictionPolicy");
		cacheConfig.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
	}
}
 
開發者ID:webdsl,項目名稱:webdsl,代碼行數:49,代碼來源:EhCacheRegionFactory.java

示例15: initCache

import net.sf.ehcache.config.CacheConfiguration; //導入方法依賴的package包/類
/**
 * 
 * 初始化緩存
 * 
 * @param cacheName
 *            緩存名稱
 * 
 * @param maxElementsInMemory
 *            元素最大數量
 * 
 * @param overflowToDisk
 *            是否持久化到硬盤
 * 
 * @param eternal
 *            是否會死亡
 * 
 * @param timeToLiveSeconds
 *            緩存存活時間
 * 
 * @param timeToIdleSeconds
 *            緩存的間隔時間
 * 
 * @return緩存
 * 
 * @throws Exception
 *             異常
 */

public static Cache initCache(String cacheName, int maxElementsInMemory,

boolean overflowToDisk, boolean eternal, long timeToLiveSeconds,

long timeToIdleSeconds) throws Exception {

	try {

		CacheManager singletonManager = CacheManager.create();

		Cache myCache = singletonManager.getCache(cacheName);

		if (myCache != null) {

			CacheConfiguration config = cache.getCacheConfiguration();

			config.setTimeToLiveSeconds(timeToLiveSeconds);

			config.setMaxElementsInMemory(maxElementsInMemory);

			config.setOverflowToDisk(overflowToDisk);

			config.setEternal(eternal);

			config.setTimeToLiveSeconds(timeToLiveSeconds);

			config.setTimeToIdleSeconds(timeToIdleSeconds);

		}

		if (myCache == null) {

			Cache memoryOnlyCache = new Cache(cacheName, maxElementsInMemory, overflowToDisk,

			eternal, timeToLiveSeconds, timeToIdleSeconds);

			singletonManager.addCache(memoryOnlyCache);

			myCache = singletonManager.getCache(cacheName);

		}

		return myCache;

	} catch (Exception e) {

		e.printStackTrace();

		throw new Exception("init cache " + cacheName + " failed!!!");

	}

}
 
開發者ID:dreajay,項目名稱:jcode,代碼行數:82,代碼來源:EHCacheUtils.java


注:本文中的net.sf.ehcache.config.CacheConfiguration.setEternal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。