本文整理匯總了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));
}
}