本文整理汇总了Java中net.sf.ehcache.config.Configuration.addDefaultCache方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.addDefaultCache方法的具体用法?Java Configuration.addDefaultCache怎么用?Java Configuration.addDefaultCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.config.Configuration
的用法示例。
在下文中一共展示了Configuration.addDefaultCache方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpGlobal
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@BeforeClass
public static void setUpGlobal() {
final Configuration config = new Configuration();
config.addDefaultCache(
new CacheConfiguration("default", Integer.MAX_VALUE)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
.overflowToDisk(false));
CACHE_MANAGER = CacheManager.create(config);
}
示例2: BlockingCacheFactory
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
public BlockingCacheFactory(int timeToLiveSeconds, int maxEntriesLocalHeap) {
Configuration cfg = new Configuration();
CacheConfiguration.CacheDecoratorFactoryConfiguration cdfc =
new CacheConfiguration.CacheDecoratorFactoryConfiguration();
cdfc.setClass(BlockingCacheDecoratorFactory.class.getName());
CacheConfiguration defaultCacheCfg = new CacheConfiguration();
defaultCacheCfg.addCacheDecoratorFactory(cdfc);
defaultCacheCfg.setTimeToLiveSeconds(timeToLiveSeconds);
defaultCacheCfg.setMaxEntriesLocalHeap(maxEntriesLocalHeap);
cfg.addDefaultCache(defaultCacheCfg);
manager = CacheManager.create(cfg);
}
示例3: IbisCacheManager
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
private IbisCacheManager() {
Configuration cacheManagerConfig = new Configuration();
String cacheDir = AppConstants.getInstance().getResolvedProperty(CACHE_DIR_KEY);
if (StringUtils.isNotEmpty(cacheDir)) {
log.debug("setting cache directory to ["+cacheDir+"]");
DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
diskStoreConfiguration.setPath(cacheDir);
cacheManagerConfig.addDiskStore(diskStoreConfiguration);
}
CacheConfiguration defaultCacheConfig = new CacheConfiguration();
cacheManagerConfig.addDefaultCache(defaultCacheConfig);
cacheManager= new CacheManager(cacheManagerConfig);
}
示例4: init
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void init(String name) throws Exception {
if ((directoryService != null) && directoryService.isStarted()) {
return;
}
directoryService.setInstanceId(name);
// instance layout
InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
if (instanceLayout.getInstanceDirectory().exists()) {
try {
FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
} catch (IOException e) {
LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
}
}
directoryService.setInstanceLayout(instanceLayout);
// EhCache in disabled-like-mode
Configuration ehCacheConfig = new Configuration();
CacheConfiguration defaultCache = new CacheConfiguration("default", 1).eternal(false).timeToIdleSeconds(30)
.timeToLiveSeconds(30).overflowToDisk(false);
ehCacheConfig.addDefaultCache(defaultCache);
CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig));
directoryService.setCacheService(cacheService);
// Init the schema
// SchemaLoader loader = new SingleLdifSchemaLoader();
SchemaLoader loader = new JarLdifSchemaLoader();
SchemaManager schemaManager = new DefaultSchemaManager(loader);
schemaManager.loadAllEnabled();
ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
for (LdapComparator<?> comparator : comparatorRegistry) {
if (comparator instanceof NormalizingComparator) {
((NormalizingComparator) comparator).setOnServer();
}
}
directoryService.setSchemaManager(schemaManager);
InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
schemaPartition.setWrappedPartition(inMemorySchemaPartition);
directoryService.setSchemaPartition(schemaPartition);
List<Throwable> errors = schemaManager.getErrors();
if (errors.size() != 0) {
throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
}
// Init system partition
Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(),
directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500,
new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
systemPartition.setSchemaManager(directoryService.getSchemaManager());
partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
directoryService.setSystemPartition(systemPartition);
directoryService.startup();
}
示例5: 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));
}
}
示例6: init
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void init(String name) throws Exception {
if ((directoryService == null) || directoryService.isStarted()) {
return;
}
directoryService.setInstanceId(name);
// instance layout
InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
if (instanceLayout.getInstanceDirectory().exists()) {
try {
FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
} catch (IOException e) {
LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
}
}
directoryService.setInstanceLayout(instanceLayout);
// EhCache in disabled-like-mode
Configuration ehCacheConfig = new Configuration();
CacheConfiguration defaultCache = new CacheConfiguration("default", 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
ehCacheConfig.addDefaultCache(defaultCache);
CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig));
directoryService.setCacheService(cacheService);
// Init the schema
// SchemaLoader loader = new SingleLdifSchemaLoader();
SchemaLoader loader = new JarLdifSchemaLoader();
SchemaManager schemaManager = new DefaultSchemaManager(loader);
schemaManager.loadAllEnabled();
ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
for (LdapComparator<?> comparator : comparatorRegistry) {
if (comparator instanceof NormalizingComparator) {
((NormalizingComparator) comparator).setOnServer();
}
}
directoryService.setSchemaManager(schemaManager);
InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
schemaPartition.setWrappedPartition(inMemorySchemaPartition);
directoryService.setSchemaPartition(schemaPartition);
List<Throwable> errors = schemaManager.getErrors();
if (errors.size() != 0) {
throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
}
// Init system partition
Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
systemPartition.setSchemaManager(directoryService.getSchemaManager());
partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
directoryService.setSystemPartition(systemPartition);
directoryService.startup();
}
示例7: init
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void init(String name) throws Exception {
if ((directoryService != null) && directoryService.isStarted()) {
return;
}
directoryService.setInstanceId(name);
// instance layout
InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
if (instanceLayout.getInstanceDirectory().exists()) {
try {
FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
} catch (IOException e) {
LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
}
}
directoryService.setInstanceLayout(instanceLayout);
// EhCache in disabled-like-mode
Configuration ehCacheConfig = new Configuration();
CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 1).eternal(false).timeToIdleSeconds(30)
.timeToLiveSeconds(30).overflowToDisk(false);
ehCacheConfig.addDefaultCache(defaultCache);
cacheManager = new CacheManager(ehCacheConfig);
CacheService cacheService = new CacheService(cacheManager);
directoryService.setCacheService(cacheService);
// Init the schema
// SchemaLoader loader = new SingleLdifSchemaLoader();
SchemaLoader loader = new JarLdifSchemaLoader();
SchemaManager schemaManager = new DefaultSchemaManager(loader);
schemaManager.loadAllEnabled();
ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
for (LdapComparator<?> comparator : comparatorRegistry) {
if (comparator instanceof NormalizingComparator) {
((NormalizingComparator) comparator).setOnServer();
}
}
directoryService.setSchemaManager(schemaManager);
InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
schemaPartition.setWrappedPartition(inMemorySchemaPartition);
directoryService.setSchemaPartition(schemaPartition);
List<Throwable> errors = schemaManager.getErrors();
if (errors.size() != 0) {
throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
}
// Init system partition
Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "system",
ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(),
"system"));
systemPartition.setSchemaManager(directoryService.getSchemaManager());
partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
directoryService.setSystemPartition(systemPartition);
directoryService.startup();
}
示例8: 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));
}
}