本文整理汇总了Java中net.sf.ehcache.constructs.blocking.SelfPopulatingCache类的典型用法代码示例。如果您正苦于以下问题:Java SelfPopulatingCache类的具体用法?Java SelfPopulatingCache怎么用?Java SelfPopulatingCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelfPopulatingCache类属于net.sf.ehcache.constructs.blocking包,在下文中一共展示了SelfPopulatingCache类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectType
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Predict the particular {@code Ehcache} implementation that will be returned from
* {@link #getObject()} based on logic in {@link #createCache()} and
* {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
*/
@Override
public Class<? extends Ehcache> getObjectType() {
if (this.cache != null) {
return this.cache.getClass();
}
if (this.cacheEntryFactory != null) {
if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
return UpdatingSelfPopulatingCache.class;
}
else {
return SelfPopulatingCache.class;
}
}
if (this.blocking) {
return BlockingCache.class;
}
return Cache.class;
}
示例2: testEhCacheFactoryBeanWithSelfPopulatingCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() throws Exception {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setCacheEntryFactory(new CacheEntryFactory() {
@Override
public Object createEntry(Object key) throws Exception {
return key;
}
});
assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof SelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getValue());
}
finally {
cacheManagerFb.destroy();
}
}
示例3: getObjectType
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Predict the particular {@code Ehcache} implementation that will be returned from
* {@link #getObject()} based on logic in {@link #createCache()} and
* {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
*/
public Class<? extends Ehcache> getObjectType() {
if (this.cache != null) {
return this.cache.getClass();
}
if (this.cacheEntryFactory != null) {
if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
return UpdatingSelfPopulatingCache.class;
}
else {
return SelfPopulatingCache.class;
}
}
if (this.blocking) {
return BlockingCache.class;
}
return Cache.class;
}
示例4: testEhCacheFactoryBeanWithSelfPopulatingCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
public void testEhCacheFactoryBeanWithSelfPopulatingCache() throws Exception {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setCacheEntryFactory(new CacheEntryFactory() {
@Override
public Object createEntry(Object key) throws Exception {
return key;
}
});
assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof SelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getValue());
}
finally {
cacheManagerFb.destroy();
}
}
示例5: createLoadingCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
@Override
public <K, V> LoadingBenchmarkCache<K, V> createLoadingCache(
final Class<K> _keyType, final Class<V> _valueType,
final int _maxElements, final BenchmarkCacheSource<K, V> _source) {
MyLoadingBenchmarkCache c = new MyLoadingBenchmarkCache();
Ehcache ehc = new Cache(createCacheConfiguration(_maxElements));
getManager().addCache(ehc);
int _cpus = Runtime.getRuntime().availableProcessors();
int _stripes = cpuCount2StripeCount(_cpus * 2);
c.cache = new SelfPopulatingCache(ehc,
_stripes,
new CacheEntryFactory() {
@Override
public Object createEntry(final Object key) throws Exception {
return _source.load((K) key);
}
});
c.size = _maxElements;
return c;
}
示例6: decorateCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Decorate the given Cache, if necessary.
* @param cache the raw Cache object, based on the configuration of this FactoryBean
* @return the (potentially decorated) cache object to be registered with the CacheManager
*/
protected Ehcache decorateCache(Ehcache cache) {
if (this.cacheEntryFactory != null) {
if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
}
else {
return new SelfPopulatingCache(cache, this.cacheEntryFactory);
}
}
if (this.blocking) {
return new BlockingCache(cache);
}
return cache;
}
示例7: AbstractEHCachingMaster
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Creates an instance over an underlying source specifying the cache manager.
*
* @param name the cache name, not empty
* @param underlying the underlying source, not null
* @param cacheManager the cache manager, not null
*/
public AbstractEHCachingMaster(final String name, final AbstractChangeProvidingMaster<D> underlying, final CacheManager cacheManager) {
ArgumentChecker.notEmpty(name, "name");
ArgumentChecker.notNull(underlying, "underlying");
ArgumentChecker.notNull(cacheManager, "cacheManager");
_underlying = underlying;
_cacheManager = cacheManager;
// 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))));
}
_uidToDocumentCache = new SelfPopulatingCache(_cacheManager.getCache(name + CACHE_NAME_SUFFIX),
new UidToDocumentCacheEntryFactory<>(_underlying));
getCacheManager().replaceCacheWithDecoratedCache(_cacheManager.getCache(name + CACHE_NAME_SUFFIX),
getUidToDocumentCache());
// Listen to change events from underlying, clean this cache accordingly and relay events to our change listeners
_changeManager = new BasicChangeManager();
_changeListener = new ChangeListener() {
@Override
public void entityChanged(ChangeEvent event) {
final ObjectId oid = event.getObjectId();
final Instant versionFrom = event.getVersionFrom();
final Instant versionTo = event.getVersionTo();
cleanCaches(oid, versionFrom, versionTo);
_changeManager.entityChanged(event.getType(), event.getObjectId(),
event.getVersionFrom(), event.getVersionTo(), event.getVersionInstant());
}
};
underlying.changeManager().addChangeListener(_changeListener);
}
示例8: decorateCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Decorate the given Cache, if necessary.
* <p>The default implementation simply returns the given cache object as-is.
*
* @param cache the raw Cache object, based on the configuration of this FactoryBean
* @param model the model containing the name of the cache to retrieve
* @return the (potentially decorated) cache object to be registered with the CacheManager
*/
protected Ehcache decorateCache(Cache cache, EhCacheCachingModel model) {
if (model.getCacheEntryFactory() != null) {
if (model.getCacheEntryFactory() instanceof UpdatingCacheEntryFactory) {
return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) model.getCacheEntryFactory());
} else {
return new SelfPopulatingCache(cache, model.getCacheEntryFactory());
}
}
if (model.isBlocking()) {
return new BlockingCache(cache);
}
return cache;
}
示例9: createInMemoryCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
public static Ehcache createInMemoryCache(String cacheName, CacheEntryFactory entryFactory, int maxElements) {
CacheManager manager = CacheManager.getInstance();
Ehcache cache = getCache(cacheName);
if (cache == null) {
// Create the cache
cache = new Cache(cacheName,
maxElements,
memoryStoreEvictionPolicy, overflowToDisk,
diskStorePath, eternal, timeToLive,
timeToIdle, diskPersistent,
diskExpiryThreadIntervalSeconds, null);
// Associate the cacheEntryFactory with the cache
SelfPopulatingCache selfPopulatingCache = new SelfPopulatingCache(cache,
entryFactory);
// Add any additional listener properties
if (manager.getCachePeerListener("RMI") != null) {
LOG.info("Setting RMI properties");
Properties properties = new Properties();
properties.put("replicateAsynchronously", "true");
properties.put("replicatePuts", "false");
properties.put("replicateUpdates", "true");
properties.put("replicateRemovals", "true");
properties.put("replicateUpdatesViaCopy", "false");
properties.put("asynchronousReplicationIntervalMillis", "1000");
RMICacheReplicatorFactory factory = new RMICacheReplicatorFactory();
CacheEventListener listener = factory.createCacheEventListener(properties);
selfPopulatingCache.getCacheEventNotificationService().registerListener(listener);
RMIBootstrapCacheLoaderFactory bootstrapFactory = new RMIBootstrapCacheLoaderFactory();
BootstrapCacheLoader bootstrapCacheLoader = bootstrapFactory.createBootstrapCacheLoader(new Properties());
selfPopulatingCache.setBootstrapCacheLoader(bootstrapCacheLoader);
LOG.debug("RMI enabled");
}
// Make the cache available
manager.addCache(selfPopulatingCache);
LOG.info("cache created: " + cache.getName());
}
return cache;
}
示例10: createCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
public static SelfPopulatingCache createCache(String ehcachename, CacheEntryFactory cu) {
Logger.getLogger(SPCacheFactory.class.getName()).log(Level.INFO, "Setting up cache... {0}", ehcachename);
MulticastKeepaliveHeartbeatSender.setHeartBeatInterval(1000);
Logger.getLogger(SPCacheFactory.class.getName()).log(Level.INFO, "Waiting cluster {0}", manager.getName());
SPCacheFactory.waitForClusterMembership(10, TimeUnit.SECONDS, Collections.singleton(ehcachename), manager);
Logger.getLogger(SPCacheFactory.class.getName()).log(Level.INFO, "Cluster connected.");
Cache orig_ehcache = manager.getCache(ehcachename);
if (orig_ehcache == null) {
return null;
}
orig_ehcache.bootstrap();
SelfPopulatingCache ehcache = new SelfPopulatingCache(orig_ehcache, cu);
ehcache.bootstrap();
return ehcache;
}
示例11: FrontCacheUpdater
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
public FrontCacheUpdater(SelfPopulatingCache back) {
backCache = back;
}
示例12: MyDataAccessClass
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
public MyDataAccessClass(Ehcache cache)
{
cache.registerCacheWriter(new MyCacheWriter());
this.cache = new SelfPopulatingCache(cache,new MyCacheEntryFactory());
}
示例13: EhCacheCache
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; //导入依赖的package包/类
/**
* Create new cache.
*
* @param cache Cache where computed values are stored.
* @param parser Parser to compute concrete {@link ReadableUserAgent} instances.
*/
public EhCacheCache(Ehcache cache, UserAgentStringParser parser) {
super(parser);
this.cache = new SelfPopulatingCache(cache, new EhCacheEntryFactory(parser));
}