google-code-export / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

when use customerCache have to set evictionClass #352

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i used EhCache in mapper.xml , i found that "hits radio" always appears in log 
file.

at last i found there code:
in org.apache.ibatis.builder.MapperBuilderAssistant
---------------------------------------------------------
 public Cache useNewCache(Class<? extends Cache> typeClass,
                           Class<? extends Cache> evictionClass,
                           Long flushInterval,
                           Integer size,
                           boolean readWrite,
                           Properties props) {
    typeClass = valueOrDefault(typeClass, PerpetualCache.class);
    evictionClass = valueOrDefault(evictionClass, LruCache.class);
    // evictionClass has been set even if i used ehcache
    Cache cache = new CacheBuilder(currentNamespace)
        .implementation(typeClass)
        .addDecorator(evictionClass)
        .clearInterval(flushInterval)
        .size(size)
        .readWrite(readWrite)
        .properties(props)
        .build();
    ...
---------------------------------------------------------
then in org.apache.ibatis.mapping.CacheBuilder
---------------------------------------------------------
  public Cache build() {
    ...
    for (Class<? extends Cache> decorator : decorators) {
      cache = newCacheDecoratorInstance(decorator, cache);
      //i got a LruCache
      setCacheProperties(cache);
    }
    cache = setStandardDecorators(cache);
    // decorated
    return cache;
  }
---------------------------------------------------------

what ever cache i used ,it has to be decorated.

Original issue reported on code.google.com by shiym...@gmail.com on 22 Jun 2011 at 2:17

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
3.0.4  mybatis-spring-1.0.0

Please describe the problem.  Unit tests are best!
cache can't out of decorated

What is the expected output? What do you see instead?
expected output: ehcache logging 
instead: mybatis LoggingCache log

Please provide any additional information below.
as above said, evictionClass has to be set or with a default value LruCache.
then decorator worked.

Original comment by shiym...@gmail.com on 23 Jun 2011 at 2:35

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 18 Jan 2012 at 11:42

GoogleCodeExporter commented 9 years ago
fixed in r4590. Decorators are no longer applied to custom caches.

Thanks for the report!

Original comment by eduardo.macarron on 18 Jan 2012 at 12:37

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 18 Jan 2012 at 12:37

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 5 Feb 2012 at 6:56

GoogleCodeExporter commented 9 years ago
Eduardo, you said that this decoration should apply to custom caches.
However the ehcache, hazelnutcache,memcache and oscache impl in the plugin 
project also suffer from this problem, as it's class also start with 
org.apache.ibatis...

Original comment by vonk.th...@gmail.com on 26 Oct 2012 at 11:22

GoogleCodeExporter commented 9 years ago
Vonk, they start with org.mybatis... aren't they?

Original comment by eduardo.macarron on 26 Oct 2012 at 11:29

GoogleCodeExporter commented 9 years ago
Yes. They start with "org.apache.ibatis"
But they don't implement the decorator option. They use the String id 
constructor

Error parsing Mapper XML. Cause: org.apache.ibatis.cache.CacheException: 
Invalid cache decorator (class org.mybatis.caches.ehcache.EhcacheCache).  Cache 
decorators must have a constructor that takes a Cache instance as a parameter.  
Cause: java.lang.NoSuchMethodException: 

Original comment by vonk.th...@gmail.com on 26 Oct 2012 at 11:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Ow wait, I'm now overlooking something. (Looking again at the error trace.
Maybe multiple mybatis versions on my classpath...

Original comment by vonk.th...@gmail.com on 26 Oct 2012 at 11:57