本文整理汇总了Java中net.sf.ehcache.config.PersistenceConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceConfiguration类的具体用法?Java PersistenceConfiguration怎么用?Java PersistenceConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceConfiguration类属于net.sf.ehcache.config包,在下文中一共展示了PersistenceConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EhCacheWrapper
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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: initCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
public static void initCache(String bucket) {
if (manager == null) {
load();
}
if (manager.getCache(bucket) != null) {
return;
}
CacheConfiguration config = new CacheConfiguration(bucket, 10000);
//config.setDiskPersistent(false);
//config.setMaxElementsOnDisk(0);
//config.setMaxBytesLocalDisk(0L);
config.setOverflowToOffHeap(false);
PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration();
persistenceConfiguration.strategy(PersistenceConfiguration.Strategy.NONE);
config.persistence(persistenceConfiguration);
manager.addCache(new Cache(config));
}
示例3: NcwmsCatalogue
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
public NcwmsCatalogue(NcwmsConfig config) throws IOException {
super(config, new SimpleLayerNameMapper());
this.styleCatalogue = SldTemplateStyleCatalogue.getStyleCatalogue();
if (cacheManager.cacheExists(CACHE_NAME) == false) {
/*
* Configure cache
*/
CacheConfiguration cacheConfig = new CacheConfiguration(CACHE_NAME, MAX_HEAP_ENTRIES)
.eternal(true)
.memoryStoreEvictionPolicy(EVICTION_POLICY)
.persistence(new PersistenceConfiguration().strategy(PERSISTENCE_STRATEGY))
.transactionalMode(TRANSACTIONAL_MODE);
dynamicDatasetCache = new Cache(cacheConfig);
cacheManager.addCache(dynamicDatasetCache);
} else {
dynamicDatasetCache = cacheManager.getCache(CACHE_NAME);
}
}
示例4: ServletCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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);
}
示例5: setCacheValue
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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));
}
示例6: getOrCreateCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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;
}
示例7: createMemCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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: LocalCacheManager
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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());
}
}
}
示例9: createCacheConfiguration
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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.config.PersistenceConfiguration; //导入依赖的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: ehcacheTicketsCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
@Lazy
@Autowired
@Bean
public EhCacheFactoryBean ehcacheTicketsCache(@Qualifier("cacheManager") final CacheManager manager) {
final EhcacheProperties ehcacheProperties = casProperties.getTicket().getRegistry().getEhcache();
final EhCacheFactoryBean bean = new EhCacheFactoryBean();
bean.setCacheName(ehcacheProperties.getCacheName());
bean.setCacheEventListeners(Collections.singleton(ticketRMISynchronousCacheReplicator()));
bean.setTimeToIdle(ehcacheProperties.getCacheTimeToIdle());
bean.setTimeToLive(ehcacheProperties.getCacheTimeToLive());
bean.setCacheManager(manager);
bean.setBootstrapCacheLoader(ticketCacheBootstrapCacheLoader());
bean.setDiskExpiryThreadIntervalSeconds(ehcacheProperties.getDiskExpiryThreadIntervalSeconds());
bean.setEternal(ehcacheProperties.isEternal());
bean.setMaxEntriesLocalHeap(ehcacheProperties.getMaxElementsInMemory());
bean.setMaxEntriesInCache(ehcacheProperties.getMaxElementsInCache());
bean.setMaxEntriesLocalDisk(ehcacheProperties.getMaxElementsOnDisk());
bean.setMemoryStoreEvictionPolicy(ehcacheProperties.getMemoryStoreEvictionPolicy());
final PersistenceConfiguration c = new PersistenceConfiguration();
c.strategy(ehcacheProperties.getPersistence());
c.setSynchronousWrites(ehcacheProperties.isSynchronousWrites());
bean.persistence(c);
return bean;
}
示例12: initCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
public static void initCache(String bucket) {
if (manager == null) {
load();
}
if (manager.getCache(bucket) != null) {
return;
}
synchronized(manager) {
if (manager.getCache(bucket) != null) {
return;
}
CacheConfiguration config = new CacheConfiguration();
config.setName(bucket);
// We have to do this way because there is no way to programmatically configure the
// sizeOfEngine
System.setProperty("net.sf.ehcache.sizeofengine.stallionLocalMemoryCache." + bucket, "io.stallion.dataAccess.filtering.EstimatedSizeOfEngine");
// Max cache size is 100MB
config.setMaxBytesLocalHeap(100 * 1000 * 1000L);
//config.setDiskPersistent(false);
//config.setMaxElementsOnDisk(0);
//config.setMaxBytesLocalDisk(0L);
config.setOverflowToOffHeap(false);
PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration();
persistenceConfiguration.strategy(PersistenceConfiguration.Strategy.NONE);
config.persistence(persistenceConfiguration);
manager.addCache(new Cache(config));
}
}
示例13: initCache
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
public static void initCache(String bucket) {
if (manager == null) {
load();
}
if (manager.getCache(bucket) != null) {
return;
}
// We have to do this way because there is no way to programmmatically configured the
// sizeOfEngine
System.setProperty("net.sf.ehcache.sizeofengine.stallionFilterCache." + bucket, "io.stallion.dataAccess.filtering.EstimatedSizeOfEngine");
CacheConfiguration config = new CacheConfiguration();
config.setName(bucket);
// Max cache size is very approximately, 50MB
config.setMaxBytesLocalHeap(Settings.instance().getFilterCacheSize());
//config.setDiskPersistent(false);
//config.setMaxElementsOnDisk(0);
//config.setMaxBytesLocalDisk(0L);
config.setOverflowToOffHeap(false);
PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration();
persistenceConfiguration.strategy(PersistenceConfiguration.Strategy.NONE);
config.persistence(persistenceConfiguration);
//SizeOfPolicyConfiguration sizeOfPolicyConfiguration = new SizeOfPolicyConfiguration();
//sizeOfPolicyConfiguration.
//config.addSizeOfPolicy();
//config.set
Cache cache = new Cache(config);
manager.addCache(cache);
//Cache cache = manager.getCache(bucket);
//CacheConfiguration config = cache.getCacheConfiguration();
//config.setMaxBytesLocalHeap(150000000L);
}
示例14: IndexedCollectionAdapter
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的package包/类
public IndexedCollectionAdapter(BananaRama parent){
//This must be configurable in the future
final Configuration conf = ConfigurationFactory
.parseConfiguration();
conf.getDefaultCacheConfiguration()
.getPersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.NONE);
cacheManager = CacheManager.newInstance(conf);
cache = cacheManager.addCacheIfAbsent(CACHE_NAME);
this.parent = parent;
}
示例15: PersistQueue
import net.sf.ehcache.config.PersistenceConfiguration; //导入依赖的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());
}
}