org.apache.ibatis.cache.decorators.LruCache Java Examples
The following examples show how to use
org.apache.ibatis.cache.decorators.LruCache.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapperBuilderAssistant.java From mybaties with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: MapperBuilderAssistant.java From mybatis with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: Configuration.java From Shop-for-JavaWeb with MIT License | 5 votes |
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); }
Example #4
Source File: CacheBuilder.java From mybaties with Apache License 2.0 | 5 votes |
private void setDefaultImplementations() { //又是一重保险,如果为null则设默认值,和XMLMapperBuilder.cacheElement以及MapperBuilderAssistant.useNewCache逻辑重复了 if (implementation == null) { implementation = PerpetualCache.class; if (decorators.isEmpty()) { decorators.add(LruCache.class); } } }
Example #5
Source File: Configuration.java From mybaties with Apache License 2.0 | 5 votes |
public Configuration() { //注册更多的类型别名,至于为何不直接在TypeAliasRegistry里注册,还需进一步研究 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); }
Example #6
Source File: LruCacheTest.java From mybaties with Apache License 2.0 | 5 votes |
@Test public void shouldRemoveLeastRecentlyUsedItemInBeyondFiveEntries() { LruCache cache = new LruCache(new PerpetualCache("default")); cache.setSize(5); for (int i = 0; i < 5; i++) { cache.putObject(i, i); } assertEquals(0, cache.getObject(0)); cache.putObject(5, 5); assertNull(cache.getObject(1)); assertEquals(5, cache.getSize()); }
Example #7
Source File: LruCacheTest.java From mybaties with Apache License 2.0 | 5 votes |
@Test public void shouldRemoveItemOnDemand() { Cache cache = new LruCache(new PerpetualCache("default")); cache.putObject(0, 0); assertNotNull(cache.getObject(0)); cache.removeObject(0); assertNull(cache.getObject(0)); }
Example #8
Source File: LruCacheTest.java From mybaties with Apache License 2.0 | 5 votes |
@Test public void shouldFlushAllItemsOnDemand() { Cache cache = new LruCache(new PerpetualCache("default")); for (int i = 0; i < 5; i++) { cache.putObject(i, i); } assertNotNull(cache.getObject(0)); assertNotNull(cache.getObject(4)); cache.clear(); assertNull(cache.getObject(0)); assertNull(cache.getObject(4)); }
Example #9
Source File: CacheBuilder.java From mybatis with Apache License 2.0 | 5 votes |
private void setDefaultImplementations() { //又是一重保险,如果为null则设默认值,和XMLMapperBuilder.cacheElement以及MapperBuilderAssistant.useNewCache逻辑重复了 if (implementation == null) { implementation = PerpetualCache.class; if (decorators.isEmpty()) { decorators.add(LruCache.class); } } }
Example #10
Source File: Configuration.java From mybatis with Apache License 2.0 | 5 votes |
public Configuration() { //注册更多的类型别名,至于为何不直接在TypeAliasRegistry里注册,还需进一步研究 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); }
Example #11
Source File: LruCacheTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void shouldRemoveLeastRecentlyUsedItemInBeyondFiveEntries() { LruCache cache = new LruCache(new PerpetualCache("default")); cache.setSize(5); for (int i = 0; i < 5; i++) { cache.putObject(i, i); } assertEquals(0, cache.getObject(0)); cache.putObject(5, 5); assertNull(cache.getObject(1)); assertEquals(5, cache.getSize()); }
Example #12
Source File: LruCacheTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void shouldRemoveItemOnDemand() { Cache cache = new LruCache(new PerpetualCache("default")); cache.putObject(0, 0); assertNotNull(cache.getObject(0)); cache.removeObject(0); assertNull(cache.getObject(0)); }
Example #13
Source File: LruCacheTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void shouldFlushAllItemsOnDemand() { Cache cache = new LruCache(new PerpetualCache("default")); for (int i = 0; i < 5; i++) { cache.putObject(i, i); } assertNotNull(cache.getObject(0)); assertNotNull(cache.getObject(4)); cache.clear(); assertNull(cache.getObject(0)); assertNull(cache.getObject(4)); }