本文整理汇总了Java中net.sf.ehcache.config.CacheConfiguration.setTimeToIdleSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfiguration.setTimeToIdleSeconds方法的具体用法?Java CacheConfiguration.setTimeToIdleSeconds怎么用?Java CacheConfiguration.setTimeToIdleSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.config.CacheConfiguration
的用法示例。
在下文中一共展示了CacheConfiguration.setTimeToIdleSeconds方法的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: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: configureCache
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
private void configureCache() {
CacheManager singletonManager;
try {
InputStream inputStream = this.getClass().getResourceAsStream("/ehcache.xml");
singletonManager = CacheManager.newInstance(inputStream);
} catch (Exception e) {
singletonManager = CacheManager.create();
singletonManager.addCache(CACHE_NAME);
cache.getCacheConfiguration();
cache = singletonManager.getCache(CACHE_NAME);
CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
cacheConfiguration.setTimeToIdleSeconds(300);
cacheConfiguration.setTimeToLiveSeconds(300);
e.printStackTrace();
}
cache = singletonManager.getCache(CACHE_NAME);
}
示例9: testCacheExpiration
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Test
public void testCacheExpiration() throws Exception {
Ehcache cache = CacheManager.getInstance().getEhcache("org.firepick.firebom.part.Part");
CacheConfiguration configuration = cache.getCacheConfiguration();
long idleTime = configuration.getTimeToIdleSeconds();
long liveTime = configuration.getTimeToLiveSeconds();
configuration.setTimeToIdleSeconds(1);
configuration.setTimeToLiveSeconds(1);
URL url = new URL("http://www.mcmaster.com/#91290A115");
Part part1 = PartFactory.getInstance().createPart(url);
Part part2 = PartFactory.getInstance().createPart(url);
assertEquals(part1, part2);
Thread.sleep(2000);
Part part3 = PartFactory.getInstance().createPart(url);
assert (part1 != part3);
configuration.setTimeToIdleSeconds(idleTime);
configuration.setTimeToLiveSeconds(liveTime);
}
示例10: getTicket
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
@Override
public Ticket getTicket(final String ticketIdToGet) {
final String ticketId = encodeTicketId(ticketIdToGet);
if (ticketId == null) {
return null;
}
final Element element = this.ehcacheTicketsCache.get(ticketId);
if (element == null) {
LOGGER.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
final Ticket ticket = decodeTicket((Ticket) element.getObjectValue());
final CacheConfiguration config = new CacheConfiguration();
config.setTimeToIdleSeconds(ticket.getExpirationPolicy().getTimeToIdle());
config.setTimeToLiveSeconds(ticket.getExpirationPolicy().getTimeToLive());
if (element.isExpired(config) || ticket.isExpired()) {
LOGGER.debug("Ticket [{}] has expired", ticket.getId());
this.ehcacheTicketsCache.evictExpiredElements();
this.ehcacheTicketsCache.flush();
return null;
}
return ticket;
}
示例11: 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发送订阅缓存变更消息
}
}
示例12: 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);
}
示例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);
}
示例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);
}
}
示例15: ehCacheManager
import net.sf.ehcache.config.CacheConfiguration; //导入方法依赖的package包/类
/**
* Returns instance of CacheManager.
* @return net.sf.ehcache.CacheManager
*/
@Bean(destroyMethod = "shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
//creates CacheCOnfiguration object
CacheConfiguration cacheConfiguration1m = new CacheConfiguration();
//Sets global name of cache object ame
//This must be unique. The / character is illegal.
cacheConfiguration1m.setName("mundoCache");
cacheConfiguration1m.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration1m.setMaxEntriesLocalHeap(10000);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration1m.setTimeToLiveSeconds(60);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration1m.setTimeToIdleSeconds(30);
// net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
// config.addCache(cacheConfiguration);
//creates CacheCOnfiguration object
CacheConfiguration cacheConfiguration1h = new CacheConfiguration();
//Sets global name of cache object ame
//This must be unique. The / character is illegal.
cacheConfiguration1h.setName("mundo1hCache");
cacheConfiguration1h.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration1h.setMaxEntriesLocalHeap(10000);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration1h.setTimeToLiveSeconds(3600);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration1h.setTimeToIdleSeconds(1800);
CacheConfiguration cacheConfiguration12h = new CacheConfiguration();
//Sets global name of cache object ame
//This must be unique. The / character is illegal.
cacheConfiguration12h.setName("mundo12hCache");
cacheConfiguration12h.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration12h.setMaxEntriesLocalHeap(10000);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration12h.setTimeToLiveSeconds(43200);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration12h.setTimeToIdleSeconds(21600);
CacheConfiguration cacheConfiguration24h = new CacheConfiguration();
//Sets global name of cache object ame
//This must be unique. The / character is illegal.
cacheConfiguration24h.setName("mundo24hCache");
cacheConfiguration24h.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration24h.setMaxEntriesLocalHeap(10000);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration24h.setTimeToLiveSeconds(86400);
//Sets the time to idle for an element before it expires.
//Is only used if the element is not eternal.
cacheConfiguration24h.setTimeToIdleSeconds(43200);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(cacheConfiguration1m);
config.addCache(cacheConfiguration1h);
config.addCache(cacheConfiguration12h);
config.addCache(cacheConfiguration24h);
return net.sf.ehcache.CacheManager.newInstance(config);
}