本文整理汇总了Java中net.sf.ehcache.config.CacheConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java CacheConfiguration类的具体用法?Java CacheConfiguration怎么用?Java CacheConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheConfiguration类属于net.sf.ehcache.config包,在下文中一共展示了CacheConfiguration类的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: afterPropertiesSet
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
throw new BeanInstantiationException(this.getClass(),
"Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
}
if (logger.isDebugEnabled()) {
CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());
config = this.ticketGrantingTicketsCache.getCacheConfiguration();
logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
.getName());
}
}
示例3: EhCacheTicketRegistry
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的package包/类
/**
* Instantiates a new EhCache ticket registry.
*
* @param ticketCache the ticket cache
* @param cipher the cipher
*/
public EhCacheTicketRegistry(final Cache ticketCache, final CipherExecutor cipher) {
this.ehcacheTicketsCache = ticketCache;
setCipherExecutor(cipher);
LOGGER.info("Setting up Ehcache Ticket Registry...");
Assert.notNull(this.ehcacheTicketsCache, "Ehcache Tickets cache cannot nbe null");
if (LOGGER.isDebugEnabled()) {
final CacheConfiguration config = this.ehcacheTicketsCache.getCacheConfiguration();
LOGGER.debug("TicketCache.maxEntriesLocalHeap=[{}]", config.getMaxEntriesLocalHeap());
LOGGER.debug("TicketCache.maxEntriesLocalDisk=[{}]", config.getMaxEntriesLocalDisk());
LOGGER.debug("TicketCache.maxEntriesInCache=[{}]", config.getMaxEntriesInCache());
LOGGER.debug("TicketCache.persistenceConfiguration=[{}]", config.getPersistenceConfiguration().getStrategy());
LOGGER.debug("TicketCache.synchronousWrites=[{}]", config.getPersistenceConfiguration().getSynchronousWrites());
LOGGER.debug("TicketCache.timeToLive=[{}]", config.getTimeToLiveSeconds());
LOGGER.debug("TicketCache.timeToIdle=[{}]", config.getTimeToIdleSeconds());
LOGGER.debug("TicketCache.cacheManager=[{}]", this.ehcacheTicketsCache.getCacheManager().getName());
}
}
示例4: EhCacheWrapper
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的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);
}
示例5: 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);
}
}
示例6: initCache
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的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));
}
示例7: NcwmsCatalogue
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的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);
}
}
示例8: 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);
}
示例9: EHCachingSearchCache
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的package包/类
/**
* Create a new search cache.
*
* @param name a unique name for this cache, not empty
* @param cacheManager the cache manager to use, not null
* @param searcher the CacheSearcher to use for passing search requests to an underlying master, not null
*/
public EHCachingSearchCache(String name, CacheManager cacheManager, Searcher searcher) {
ArgumentChecker.notNull(cacheManager, "cacheManager");
ArgumentChecker.notEmpty(name, "name");
ArgumentChecker.notNull(searcher, "searcher");
_cacheManager = cacheManager;
_searcher = searcher;
// Load cache configuration
if (cacheManager.getCache(name + CACHE_NAME_SUFFIX) == null) {
// If cache config not found, set up programmatically
s_logger.warn("Could not load a cache configuration for " + name + CACHE_NAME_SUFFIX
+ ", building a default configuration programmatically instead");
getCacheManager().addCache(new Cache(tweakCacheConfiguration(new CacheConfiguration(name + CACHE_NAME_SUFFIX,
10000))));
}
_searchRequestCache = cacheManager.getCache(name + CACHE_NAME_SUFFIX);
// Async prefetch executor service
ExecutorServiceFactoryBean execBean = new ExecutorServiceFactoryBean();
execBean.setNumberOfThreads(MAX_PREFETCH_CONCURRENCY);
execBean.setStyle(ExecutorServiceFactoryBean.Style.CACHED);
_executorService = execBean.getObjectCreating();
}
示例10: 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);
}
示例11: getCache
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的package包/类
@Override
public Cache getCache(String id) {
if (id == null) {
throw new IllegalArgumentException("Cache instances require an ID");
}
if (!cacheManager.cacheExists(id)) {
CacheConfiguration temp = null;
if (cacheConfiguration != null) {
temp = cacheConfiguration.clone();
} else {
// based on defaultCache
temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
}
temp.setName(id);
net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp);
cacheManager.addCache(cache);
}
return new EhcacheCache(id, cacheManager.getEhcache(id));
}
示例12: getCache
import net.sf.ehcache.config.CacheConfiguration; //导入依赖的package包/类
@Override
public Cache getCache(String id) {
if (id == null) {
throw new IllegalArgumentException("Cache instances require an ID");
}
if (!cacheManager.cacheExists(id)) {
CacheConfiguration temp = null;
if (cacheConfiguration != null) {
temp = cacheConfiguration.clone();
} else {
// based on defaultCache
temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
}
temp.setName(id);
net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp);
Ehcache instrumentCache = InstrumentedEhcache.instrument(registry, cache);
cacheManager.addCache(instrumentCache);
}
return new EhcacheCache(id, cacheManager.getEhcache(id));
}
示例13: 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);
}
示例14: 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;
}
示例15: 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;
}