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


Java CacheConfiguration.setMaxElementsInMemory方法代码示例

本文整理汇总了Java中net.sf.ehcache.config.CacheConfiguration.setMaxElementsInMemory方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfiguration.setMaxElementsInMemory方法的具体用法?Java CacheConfiguration.setMaxElementsInMemory怎么用?Java CacheConfiguration.setMaxElementsInMemory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.ehcache.config.CacheConfiguration的用法示例。


在下文中一共展示了CacheConfiguration.setMaxElementsInMemory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupCacheSource

import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
private void setupCacheSource(final boolean lazyReads, final int cacheSize, final int flushDelay) {
  InMemoryViewComputationCacheSource cache = new InMemoryViewComputationCacheSource(s_fudgeContext);
  ViewComputationCacheServer server = new ViewComputationCacheServer(cache);
  _serverSocket = new ServerSocketFudgeConnectionReceiver(cache.getFudgeContext(), server, Executors
      .newCachedThreadPool());
  _serverSocket.setLazyFudgeMsgReads(lazyReads);
  _serverSocket.start();
  _socket = new SocketFudgeConnection(cache.getFudgeContext());
  _socket.setFlushDelay(flushDelay);
  try {
    _socket.setInetAddress(InetAddress.getLocalHost());
  } catch (UnknownHostException e) {
    throw new OpenGammaRuntimeException("", e);
  }
  _socket.setPortNumber(_serverSocket.getPortNumber());

  RemoteCacheClient client = new RemoteCacheClient(_socket);
  Configuration configuration = new Configuration();
  CacheConfiguration cacheConfig = new CacheConfiguration();
  cacheConfig.setMaxElementsInMemory(cacheSize);
  configuration.setDefaultCacheConfiguration(cacheConfig);
  _cacheSource = new RemoteViewComputationCacheSource(client, new DefaultFudgeMessageStoreFactory(
      new InMemoryBinaryDataStoreFactory(), s_fudgeContext), _cacheManager);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:ServerSocketRemoteViewComputationCacheTest.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: 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: 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

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

示例6: modifyCache

import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
 * 
 * 修改缓存
 * 
 * @param cacheName
 *            缓存名
 * 
 * @param timeToLiveSeconds
 *            有效时间
 * 
 * @param maxElementsInMemory
 *            最大数量
 * 
 * @return真
 * 
 * @throws Exception
 *             异常
 */

public static boolean modifyCache(String cacheName,

long timeToLiveSeconds, int maxElementsInMemory) throws Exception {

	try {

		if (cacheName != null && !"".equals(cacheName) && timeToLiveSeconds != 0L

		&& maxElementsInMemory != 0) {

			CacheManager myManager = CacheManager.create();

			Cache myCache = myManager.getCache(cacheName);

			CacheConfiguration config = myCache.getCacheConfiguration();

			config.setTimeToLiveSeconds(timeToLiveSeconds);

			config.setMaxElementsInMemory(maxElementsInMemory);

			return true;

		} else {

			return false;

		}

	} catch (Exception e) {

		e.printStackTrace();

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

	}

}
 
开发者ID:dreajay,项目名称:jcode,代码行数:57,代码来源:EHCacheUtils.java

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