本文整理匯總了Java中net.sf.ehcache.config.Configuration.addCache方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.addCache方法的具體用法?Java Configuration.addCache怎麽用?Java Configuration.addCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.ehcache.config.Configuration
的用法示例。
在下文中一共展示了Configuration.addCache方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ServletCache
import net.sf.ehcache.config.Configuration; //導入方法依賴的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);
}
示例2: PersistQueue
import net.sf.ehcache.config.Configuration; //導入方法依賴的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());
}
}
示例3: CacheQueue
import net.sf.ehcache.config.Configuration; //導入方法依賴的package包/類
/**
* 構造函數
*
* @param block
* --是否為阻塞隊列,true是阻塞隊列,false是非阻塞隊列
* @param cacheLength
* --內存中隊列長度,值>0;
* @param persistDirPath
* --數據落地目錄(<b>注意:一個隊列對應一個目錄路徑,多個隊列共享一個目錄路徑,是不允許的,會出現數據不一致的情況! <
* /b>)
*/
public CacheQueue(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 = "cq-" + 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.LOCALTEMPSWAP));
managerConfig.addCache(mqCf);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(persistDirPath);
managerConfig.addDiskStore(dsCf);
managerConfig.setName(hcName);
// cacheManager = new CacheManager(managerConfig);
cacheManager = CacheManager.newInstance(managerConfig);
cache = cacheManager.getCache(hcName);
count = new AtomicLong(0);
}
示例4: init
import net.sf.ehcache.config.Configuration; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "unused" })
public void init() {
log.info("Loading ehcache");
// log.debug("Appcontext: " + applicationContext.toString());
try {
// instance the manager
CacheManager cm = CacheManager.getInstance();
// Use the Configuration to create our caches
Configuration configuration = new Configuration();
//set initial default cache name
String defaultCacheName = Cache.DEFAULT_CACHE_NAME;
//add the configs to a configuration
for (CacheConfiguration conf : configs) {
//set disk expiry
conf.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
//set eviction policy
conf.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
if (null == cache) {
//get first cache name and use as default
defaultCacheName = conf.getName();
configuration.addDefaultCache(conf);
} else {
configuration.addCache(conf);
}
}
//instance the helper
ConfigurationHelper helper = new ConfigurationHelper(cm, configuration);
//create the default cache
cache = helper.createDefaultCache();
//init the default
cache.initialise();
cache.bootstrap();
//create the un-init'd caches
Set<Cache> caches = helper.createCaches();
if (log.isDebugEnabled()) {
log.debug("Number of caches: " + caches.size() + " Default cache: " + (cache != null ? 1 : 0));
}
for (Cache nonDefaultCache : caches) {
nonDefaultCache.initialise();
nonDefaultCache.bootstrap();
//set first cache to be main local member
if (null == nonDefaultCache) {
log.debug("Default cache name: {}", defaultCacheName);
nonDefaultCache = cm.getCache(defaultCacheName);
}
}
} catch (Exception e) {
log.warn("Error on cache init", e);
}
if (log.isDebugEnabled()) {
log.debug("Cache is null? {}", (null == cache));
}
}
示例5: configure
import net.sf.ehcache.config.Configuration; //導入方法依賴的package包/類
@Override
public void configure(final Env env, final Config config, final Binder binder) {
Config ehcache = config.getConfig("ehcache");
Config caches = ehcache.getConfig("cache");
Config defcache = caches.getConfig("default");
Configuration ehconfig = new ConfigurationBuilder().build(ehcache);
ehconfig.setDefaultCacheConfiguration(new CacheConfigurationBuilder("default").build(defcache));
Config userCaches = caches.withoutPath("default");
for (Entry<String, ConfigValue> userCache : userCaches.root().entrySet()) {
ConfigValue value = userCache.getValue();
String cname = userCache.getKey();
Config ccache = ConfigFactory.empty();
if (value instanceof ConfigObject) {
ccache = ((ConfigObject) value).toConfig();
}
ehconfig.addCache(new CacheConfigurationBuilder(cname).build(ccache.withFallback(defcache)));
}
if (configurer != null) {
configurer.accept(ehconfig, config);
}
CacheManager cm = CacheManager.newInstance(ehconfig);
binder.bind(CacheManager.class).toInstance(cm);
env.onStop(cm::shutdown);
String[] names = cm.getCacheNames();
if (names.length == 1) {
// just one cache, bind it without name
binder.bind(Ehcache.class).toInstance(cm.getEhcache(names[0]));
}
// now bind each cache using it's name
for (String name : cm.getCacheNames()) {
binder.bind(Ehcache.class).annotatedWith(Names.named(name)).toInstance(cm.getEhcache(name));
}
}
示例6: init
import net.sf.ehcache.config.Configuration; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "unused" })
public void init() {
log.info("Loading ehcache");
// log.debug("Appcontext: " + applicationContext.toString());
try {
// instance the manager
CacheManager cm = CacheManager.getInstance();
// Use the Configuration to create our caches
Configuration configuration = new Configuration();
//set initial default cache name
String defaultCacheName = Cache.DEFAULT_CACHE_NAME;
//add the configs to a configuration
for (CacheConfiguration conf : configs) {
//set disk expiry
conf.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
//set eviction policy
conf.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
if (null == cache) {
//get first cache name and use as default
defaultCacheName = conf.getName();
configuration.addDefaultCache(conf);
} else {
configuration.addCache(conf);
}
}
//instance the helper
ConfigurationHelper helper = new ConfigurationHelper(cm, configuration);
//create the default cache
cache = helper.createDefaultCache();
//init the default
cache.initialise();
cache.bootstrap();
//create the un-init'd caches
Set<Cache> caches = helper.createCaches();
if (log.isDebugEnabled()) {
log.debug("Number of caches: " + caches.size() + " Default cache: " + (cache != null ? 1 : 0));
}
for (Cache nonDefaultCache : caches) {
nonDefaultCache.initialise();
nonDefaultCache.bootstrap();
//set first cache to be main local member
if (null == nonDefaultCache) {
log.debug("Default cache name: {}", defaultCacheName);
nonDefaultCache = cm.getCache(defaultCacheName);
}
}
} catch (Exception e) {
log.warn("Error on cache init", e);
}
if (log.isDebugEnabled()) {
log.debug("Cache is null? {}", (null == cache));
}
}