本文整理汇总了Java中org.apache.ibatis.cache.impl.PerpetualCache类的典型用法代码示例。如果您正苦于以下问题:Java PerpetualCache类的具体用法?Java PerpetualCache怎么用?Java PerpetualCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PerpetualCache类属于org.apache.ibatis.cache.impl包,在下文中一共展示了PerpetualCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: useNewCache
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
public Cache useNewCache(Class<? extends Cache> typeClass,
Class<? extends Cache> evictionClass,
Long flushInterval,
Integer size,
boolean readWrite,
boolean blocking,
Properties props) {
Cache cache = new CacheBuilder(currentNamespace)
.implementation(valueOrDefault(typeClass, PerpetualCache.class))
.addDecorator(valueOrDefault(evictionClass, LruCache.class))
.clearInterval(flushInterval)
.size(size)
.readWrite(readWrite)
.blocking(blocking)
.properties(props)
.build();
configuration.addCache(cache);
currentCache = cache;
return cache;
}
示例2: shouldSucceedWhenFullyQualifiedButFailDueToAmbiguity
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldSucceedWhenFullyQualifiedButFailDueToAmbiguity() {
Configuration c = new Configuration();
final String name1 = "com.mycache.MyCache";
final PerpetualCache cache1 = new PerpetualCache(name1);
c.addCache(cache1);
final String name2 = "com.other.MyCache";
final PerpetualCache cache2 = new PerpetualCache(name2);
c.addCache(cache2);
final String shortName = "MyCache";
assertEquals(cache1, c.getCache(name1));
assertEquals(cache2, c.getCache(name2));
try {
c.getCache(shortName);
fail("Exception expected.");
} catch (Exception e) {
assertTrue(e.getMessage().contains("ambiguous"));
}
}
示例3: shouldDemonstrate5LevelSuperCacheHandlesLotsOfEntriesWithoutCrashing
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldDemonstrate5LevelSuperCacheHandlesLotsOfEntriesWithoutCrashing() {
final int N = 100000;
Cache cache = new PerpetualCache("default");
cache = new LruCache(cache);
cache = new FifoCache(cache);
cache = new SoftCache(cache);
cache = new WeakCache(cache);
cache = new ScheduledCache(cache);
cache = new SerializedCache(cache);
// cache = new LoggingCache(cache);
cache = new SynchronizedCache(cache);
cache = new TransactionalCache(cache);
for (int i = 0; i < N; i++) {
cache.putObject(i, i);
((TransactionalCache) cache).commit();
Object o = cache.getObject(i);
assertTrue(o == null || i == ((Integer) o));
}
assertTrue(cache.getSize() < N);
}
示例4: shouldDemonstrateObjectsBeingCollectedAsNeeded
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() throws Exception {
final int N = 3000000;
SoftCache cache = new SoftCache(new PerpetualCache("default"));
for (int i = 0; i < N; i++) {
byte[] array = new byte[5001]; //waste a bunch of memory
array[5000] = 1;
cache.putObject(i, array);
Object value = cache.getObject(i);
if (cache.getSize() < i + 1) {
//System.out.println("Cache exceeded with " + (i + 1) + " entries.");
break;
}
}
assertTrue(cache.getSize() < N);
}
示例5: shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes() {
PerpetualCache cache = new PerpetualCache("test_cache");
assertTrue(cache.equals(cache));
assertTrue(cache.equals(new SynchronizedCache(cache)));
assertTrue(cache.equals(new SerializedCache(cache)));
assertTrue(cache.equals(new LoggingCache(cache)));
assertTrue(cache.equals(new ScheduledCache(cache)));
assertEquals(cache.hashCode(), new SynchronizedCache(cache).hashCode());
assertEquals(cache.hashCode(), new SerializedCache(cache).hashCode());
assertEquals(cache.hashCode(), new LoggingCache(cache).hashCode());
assertEquals(cache.hashCode(), new ScheduledCache(cache).hashCode());
Set<Cache> caches = new HashSet<Cache>();
caches.add(cache);
caches.add(new SynchronizedCache(cache));
caches.add(new SerializedCache(cache));
caches.add(new LoggingCache(cache));
caches.add(new ScheduledCache(cache));
assertEquals(1, caches.size());
}
示例6: shouldDemonstrateObjectsBeingCollectedAsNeeded
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() {
final int N = 3000000;
WeakCache cache = new WeakCache(new PerpetualCache("default"));
for (int i = 0; i < N; i++) {
cache.putObject(i, i);
if (cache.getSize() < i + 1) {
//System.out.println("Cache exceeded with " + (i + 1) + " entries.");
break;
}
if ((i + 1) % 100000 == 0) {
// Try performing GC.
System.gc();
}
}
assertTrue(cache.getSize() < N);
}
示例7: useNewCache
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
public Cache useNewCache(Class<? extends Cache> typeClass,
Class<? extends Cache> evictionClass,
Long flushInterval,
Integer size,
boolean readWrite,
boolean blocking,
Properties props) {
//这里面又判断了一下是否为null就用默认值,有点和XMLMapperBuilder.cacheElement逻辑重复了
typeClass = valueOrDefault(typeClass, PerpetualCache.class);
evictionClass = valueOrDefault(evictionClass, LruCache.class);
//调用CacheBuilder构建cache,id=currentNamespace
Cache cache = new CacheBuilder(currentNamespace)
.implementation(typeClass)
.addDecorator(evictionClass)
.clearInterval(flushInterval)
.size(size)
.readWrite(readWrite)
.blocking(blocking)
.properties(props)
.build();
//加入缓存
configuration.addCache(cache);
//当前的缓存
currentCache = cache;
return cache;
}
示例8: useNewCache
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
public Cache useNewCache(Class<? extends Cache> typeClass,
Class<? extends Cache> evictionClass,
Long flushInterval,
Integer size,
boolean readWrite,
boolean blocking,
Properties props) {
typeClass = valueOrDefault(typeClass, PerpetualCache.class);
evictionClass = valueOrDefault(evictionClass, LruCache.class);
Cache cache = new CacheBuilder(currentNamespace)
.implementation(typeClass)
.addDecorator(evictionClass)
.clearInterval(flushInterval)
.size(size)
.readWrite(readWrite)
.blocking(blocking)
.properties(props)
.build();
configuration.addCache(cache);
currentCache = cache;
return cache;
}
示例9: test_FifoCache
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void test_FifoCache() {
FifoCache fifoCache = new FifoCache(new PerpetualCache("test_fifo_cache"));
fifoCache.setSize(2);
assertThat(fifoCache.getSize(), equalTo(0));
fifoCache.putObject("name", "doctor");
assertThat(fifoCache.getSize(), equalTo(1));
assertThat(fifoCache.getObject("name"), equalTo("doctor"));
fifoCache.putObject("age", 2000);
assertThat(fifoCache.getSize(), equalTo(2));
fifoCache.putObject("sex", "man");
assertThat(fifoCache.getSize(), equalTo(2));
assertThat(fifoCache.getObject("name"), equalTo(null));// 第一个缓存对象被移除
}
示例10: setDefaultImplementations
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
private void setDefaultImplementations() {
if (implementation == null) {
implementation = PerpetualCache.class;
if (decorators.isEmpty()) {
decorators.add(LruCache.class);
}
}
}
示例11: Configuration
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
public Configuration() {
typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class);
typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class);
typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class);
typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class);
typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class);
typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class);
typeAliasRegistry.registerAlias("FIFO", FifoCache.class);
typeAliasRegistry.registerAlias("LRU", LruCache.class);
typeAliasRegistry.registerAlias("SOFT", SoftCache.class);
typeAliasRegistry.registerAlias("WEAK", WeakCache.class);
typeAliasRegistry.registerAlias("DB_VENDOR", VendorDatabaseIdProvider.class);
typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class);
typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class);
typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class);
typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class);
typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class);
typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class);
typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class);
typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class);
typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class);
typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class);
typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class);
languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class);
languageRegistry.register(RawLanguageDriver.class);
}
示例12: BaseExecutor
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
protected BaseExecutor(Configuration configuration, Transaction transaction) {
this.transaction = transaction;
this.deferredLoads = new ConcurrentLinkedQueue<DeferredLoad>();
this.localCache = new PerpetualCache("LocalCache");
this.localOutputParameterCache = new PerpetualCache("LocalOutputParameterCache");
this.closed = false;
this.configuration = configuration;
this.wrapper = this;
}
示例13: DeferredLoad
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
public DeferredLoad(MetaObject resultObject,
String property,
CacheKey key,
PerpetualCache localCache,
Configuration configuration,
Class<?> targetType) {
this.resultObject = resultObject;
this.property = property;
this.key = key;
this.localCache = localCache;
this.objectFactory = configuration.getObjectFactory();
this.resultExtractor = new ResultExtractor(configuration, objectFactory);
this.targetType = targetType;
}
示例14: shouldResolveBothSimpleNameAndFullyQualifiedName
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test
public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
Configuration c = new Configuration();
final String fullName = "com.mycache.MyCache";
final String shortName = "MyCache";
final PerpetualCache cache = new PerpetualCache(fullName);
c.addCache(cache);
assertEquals(cache, c.getCache(fullName));
assertEquals(cache, c.getCache(shortName));
}
示例15: shouldFailOverToMostApplicableSimpleName
import org.apache.ibatis.cache.impl.PerpetualCache; //导入依赖的package包/类
@Test(expected=IllegalArgumentException.class)
public void shouldFailOverToMostApplicableSimpleName() {
Configuration c = new Configuration();
final String fullName = "com.mycache.MyCache";
final String invalidName = "unknown.namespace.MyCache";
final PerpetualCache cache = new PerpetualCache(fullName);
c.addCache(cache);
assertEquals(cache, c.getCache(fullName));
assertEquals(cache, c.getCache(invalidName));
}