本文整理汇总了Java中net.sf.ehcache.store.MemoryStoreEvictionPolicy类的典型用法代码示例。如果您正苦于以下问题:Java MemoryStoreEvictionPolicy类的具体用法?Java MemoryStoreEvictionPolicy怎么用?Java MemoryStoreEvictionPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemoryStoreEvictionPolicy类属于net.sf.ehcache.store包,在下文中一共展示了MemoryStoreEvictionPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EhCacheWrapper
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
/**
* http://www.ehcache.org/documentation/2.8/code-samples.html#creating-caches-programmatically
*/
EhCacheWrapper(String cacheName) {
AppConfiguration.Cache config = AppConfiguration.CONFIG.getCache();
// Create a Cache specifying its configuration
cache = new Cache(
new CacheConfiguration(cacheName, config.getMaxSize())
.timeToLiveSeconds(TimeUnit.MINUTES.toSeconds(config.getLifeTime()))
.eternal(false)
.persistence(new PersistenceConfiguration().strategy(Strategy.NONE))
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
);
// The cache is not usable until it has been added
manager.addCache(cache);
}
示例2: init
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {
NonVersionedRedisSecuritySource source = new NonVersionedRedisSecuritySource(getRedisConnector().getJedisPool(), getRedisPrefix());
SecuritySource rawSource = source;
if ((getCacheManager() != null) && (getLruCacheElements() > 0)) {
Cache cache = new Cache("NonVersionedRedisSecuritySource", getLruCacheElements(), MemoryStoreEvictionPolicy.LRU, false, null, true, -1L, -1L, false, -1L, null);
getCacheManager().addCache(cache);
rawSource = new NonVersionedEHCachingSecuritySource(source, cache);
}
String rawClassifier = getCachingClassifier() != null ? getCachingClassifier() : getClassifier();
ComponentInfo sourceInfo = new ComponentInfo(SecuritySource.class, rawClassifier);
sourceInfo.addAttribute(ComponentInfoAttributes.LEVEL, 1);
sourceInfo.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteSecuritySource.class);
repo.registerComponent(sourceInfo, rawSource);
ComponentInfo redisInfo = new ComponentInfo(NonVersionedRedisSecuritySource.class, getClassifier());
redisInfo.addAttribute(ComponentInfoAttributes.LEVEL, 1);
repo.registerComponent(redisInfo, source);
if (isPublishRest()) {
repo.getRestComponents().publish(sourceInfo, new DataSecuritySourceResource(rawSource));
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:NonVersionedRedisSecuritySourceComponentFactory.java
示例3: setCacheValue
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
public void setCacheValue(String cacheName, String keyName, Collection<Attribute> attrs, int tti, int ttl) {
CacheManager manager = Context.getInstance().getCacheManager();
Cache cache = manager.getCache(cacheName);
if (cache == null) {
cache = new Cache(
new CacheConfiguration(cacheName, 1000)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
.eternal(false)
.timeToLiveSeconds(60)
.timeToIdleSeconds(60)
.diskExpiryThreadIntervalSeconds(120)
.persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP)));
manager.addCache(cache);
}
cache.put(new net.sf.ehcache.Element(keyName, attrs, false, tti, ttl));
}
示例4: getOrCreateCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
private Cache getOrCreateCache() {
// Create a singleton CacheManager using defaults
CacheManager manager = CacheManager.create();
// Create a Cache specifying its configuration
Cache c = manager.getCache(CACHE_name);
if (c == null) {
c = new Cache(new CacheConfiguration(CACHE_name,
CACHE_maxEntriesLocalHeap)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
.eternal(true)
.persistence(
new PersistenceConfiguration()
.strategy(Strategy.LOCALTEMPSWAP)));
manager.addCache(c);
}
return c;
}
示例5: initCacheEhcacheBigMemory
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
/**
* Inits the cache ehcache big memory.
*/
@SuppressWarnings("deprecation")
private static void initCacheEhcacheBigMemory() {
// Create a CacheManager using defaults
sEhcacheManager = CacheManager.create();
// Create a Cache specifying its configuration.
sEhcacheCache = new Cache(new CacheConfiguration("test", 10000)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
.overflowToDisk(false).eternal(false).timeToLiveSeconds(6000)
.timeToIdleSeconds(6000).diskPersistent(false)
.diskExpiryThreadIntervalSeconds(0).overflowToOffHeap(true)
.maxMemoryOffHeap(sBigMemorySize));
sEhcacheManager.addCache(sEhcacheCache);
}
示例6: initCacheEhcache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
/**
* Inits the cache ehcache.
*/
@SuppressWarnings("deprecation")
private static void initCacheEhcache() {
// Create a CacheManager using defaults
sEhcacheManager = CacheManager.create();
// Create a Cache specifying its configuration.
sEhcacheCache = new Cache(new CacheConfiguration("test",
(int) sCacheItemsLimit).memoryStoreEvictionPolicy(
MemoryStoreEvictionPolicy.LRU).overflowToDisk(false).eternal(
false).timeToLiveSeconds(6000).timeToIdleSeconds(6000)
.diskPersistent(false).diskExpiryThreadIntervalSeconds(0));
sEhcacheManager.addCache(sEhcacheCache);
}
示例7: LocalCacheManager
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
public LocalCacheManager(String name, int max, int exptime, boolean copyOnRead, boolean copyOnWrite) {
this.cache = CacheManager.getInstance().getCache(name);
if (cache == null) {
CacheConfiguration config =
new CacheConfiguration(name, max)
.copyOnRead(copyOnRead)
.copyOnWrite(copyOnWrite)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
.eternal(false)
.timeToLiveSeconds(exptime)
.timeToIdleSeconds(exptime)
.diskExpiryThreadIntervalSeconds(60)
.persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE));
this.cache = new Cache(config, null, null);
CacheManager.getInstance().addCache(cache);
if (logger.isInfoEnabled()) {
logger.info("Arcus k/v local cache is enabled : %s", cache.toString());
}
}
}
示例8: open
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
public void open() {
Cache configCache = new Cache(
getName(),
getMaxElementsInMemory(),
MemoryStoreEvictionPolicy.fromString(getMemoryStoreEvictionPolicy()),
isOverflowToDisk(),
null,
isEternal(),
getTimeToLiveSeconds(),
getTimeToIdleSeconds(),
isDiskPersistent(),
getDiskExpiryThreadIntervalSeconds(),
null,
null,
getMaxElementsOnDisk()
);
cacheManager=IbisCacheManager.getInstance();
cache = cacheManager.addCache(configCache);
}
示例9: createCacheConfiguration
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的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;
}
示例10: RealCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
public RealCache() {
super();
CacheManager manager = null;
synchronized (RealCache.class) {
manager = CacheManager.getInstance();
if (!manager.cacheExists("AFPDataGrabberCache")) {
Cache cache = new Cache(new CacheConfiguration("AFPDataGrabberCache", 50000).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
.eternal(true).timeToLiveSeconds(0).timeToIdleSeconds(0).persistence(new PersistenceConfiguration().strategy(Strategy.NONE)));
manager.addCache(cache);
}
}
ehcache = manager.getCache("AFPDataGrabberCache");
}
示例11: afterPropertiesSet
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的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: createLifeCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
static Cache createLifeCache(CacheManager manager, String name) {
return createCache(
manager,
name,
configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
.timeToLiveSeconds(LIFE_TIME_SEC));
}
示例13: createIdleCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
static Cache createIdleCache(CacheManager manager, String name) {
return createCache(
manager,
name,
configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
.timeToIdleSeconds(IDLE_TIME_SEC));
}
示例14: createEternalCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
static Cache createEternalCache(CacheManager manager, String name) {
return createCache(
manager,
name,
configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
.eternal(true));
}
示例15: createLifeCache
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; //导入依赖的package包/类
static Cache createLifeCache(CacheManager manager, String name) {
CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES);
configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
.timeToLiveSeconds(LIFE_TIME_SEC);
Cache cache = new Cache(configuration);
manager.addCache(cache);
return cache;
}