当前位置: 首页>>代码示例>>Java>>正文


Java PerpetualCache类代码示例

本文整理汇总了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;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:21,代码来源:MapperBuilderAssistant.java

示例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"));
  }

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:26,代码来源:SqlSessionTest.java

示例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);
  }
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:22,代码来源:SuperCacheTest.java

示例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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:SoftCacheTest.java

示例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());
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:23,代码来源:BaseCacheTest.java

示例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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:WeakCacheTest.java

示例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;
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:27,代码来源:MapperBuilderAssistant.java

示例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;
}
 
开发者ID:toulezu,项目名称:play,代码行数:23,代码来源:MapperBuilderAssistant.java

示例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));// 第一个缓存对象被移除

}
 
开发者ID:sdcuike,项目名称:spring4-2015,代码行数:20,代码来源:FifoCachePractice.java

示例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);
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:CacheBuilder.java

示例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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:34,代码来源:Configuration.java

示例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;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:10,代码来源:BaseExecutor.java

示例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;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:15,代码来源:BaseExecutor.java

示例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));
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:11,代码来源:SqlSessionTest.java

示例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));
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:11,代码来源:SqlSessionTest.java


注:本文中的org.apache.ibatis.cache.impl.PerpetualCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。