Ehcache and SLF4J error -


i new ehcache , slf4j .i using ehcache-2.6.6

i have used

slf4j-api-1.6.1 jar

slf4j-jdk14-1.6.1 jar

when extracted ehcache-2.6.6-distribution.tar these 2 jars in folder lib .

this ehcache.xml

<?xml version="1.0" encoding="utf-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:nonamespaceschemalocation="ehcache.xsd"          updatecheck="true" monitoring="autodetect"          dynamicconfig="true">       <diskstore path="java.io.tmpdir"/>      <defaultcache             maxentrieslocalheap="10000"             eternal="false"             timetoidleseconds="120"             timetoliveseconds="120"             diskspoolbuffersizemb="30"             maxentrieslocaldisk="10000000"             diskexpirythreadintervalseconds="120"             memorystoreevictionpolicy="lru"             statistics="false">         <persistence strategy="localtempswap"/>     </defaultcache>      <cache name="mycache1"            maxentrieslocalheap="10000"            maxentrieslocaldisk="1000"            eternal="false"            diskspoolbuffersizemb="20"            timetoidleseconds="300"            timetoliveseconds="600"            memorystoreevictionpolicy="lfu"            transactionalmode="off">         <persistence strategy="localtempswap"/>     </cache>  </ehcache> 

this code

package cache;  import java.util.arraylist; import java.util.list;  import net.sf.ehcache.cachemanager; import net.sf.ehcache.ehcache; import net.sf.ehcache.element;  public class ehcachewrapper {     private static cachemanager cachemanager;     private static final string cache_name = "mycache1";           private static ehcache getcache(string cachename) {         if (cachemanager == null) {             cachemanager = cachemanager.create("ehcache.xml");         }          ehcache cache = null;         if (cachemanager != null) {              cache = cachemanager.getehcache(cachename);         }          return cache;     }      public static <t> list<t> getlistfromcache( string cachename, string key, cachecreation<t> cachecreation){         list<t> = new arraylist<t>();          ehcache cache = getcache(cachename);         element element = null;         if(cache!=null){             element = cache.get(key);         }          if(element==null){             system.out.println(" : cacheutil.getlistfromcache() : element '"+key+"' has not been found in cache ---> original data.");              = cachecreation.getall();             cache.put(new element(key, all));             system.out.println(" : cacheutil.getlistfromcache() : original data element '"+key+"' has been added in cache.");           }else{             system.out.println(" : cacheutil.getlistfromcache() : element '"+key+"' has been found in cache.");               = (list<t>) element.getobjectvalue();         }         return all;      }     public list<string> getalldata1(){         return getlistfromcache( cache_name, "data1", new cachecreation<string>(){             @override             public list<string> getall(){                 system.out.println(" : usecaseclass.getalldata1() : target original method called values.");                 list<string> list = new arraylist<string>();                 list.add("data1-value1");                 list.add("data1-value2");                 list.add("data1-value3");                 list.add("data1-value4");                 return list;             }         });     }        public static void main(string[] args) {         ehcachewrapper wrappertest=new ehcachewrapper();         wrappertest.getalldata1();         try {             thread.sleep(1500);         } catch (interruptedexception e) {           }         wrappertest.getalldata1();         try {             thread.sleep(1500);         } catch (interruptedexception e) {          }         wrappertest.getalldata1();         try {             thread.sleep(1500);         } catch (interruptedexception e) {          }         } } 

when run program getting following output

slf4j: requested version 1.6 slf4j binding not compatible [1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11] slf4j: see http://www.slf4j.org/codes.html#version_mismatch further details. may 15, 2013 1:52:36 pm net.sf.ehcache.diskstorepathmanager resolveandlockifneeded warning: diskstorepath 'c:\users\toshiba\appdata\local\temp' used existing cachemanager either in same vm or in different process. diskstore path cachemanager set c:\users\toshiba\appdata\local\temp\ehcache_auto_created3199473242323720768diskstore. avoid warning consider using cachemanager factory methods create singleton cachemanager or specifying separate ehcache configuration (ehcache.xml) each cachemanager instance.  : cacheutil.getlistfromcache() : element 'data1' has not been found in cache ---> original data.  : usecaseclass.getalldata1() : target original method called values.  : cacheutil.getlistfromcache() : original data element 'data1' has been added in cache.  : cacheutil.getlistfromcache() : element 'data1' has been found in cache.  : cacheutil.getlistfromcache() : element 'data1' has been found in cache. 

though getting expected output there error in beginning saying :

slf4j: requested version 1.6 slf4j binding not compatible [1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11] slf4j: see http://www.slf4j.org/codes.html#version_mismatch further details. may 15, 2013 1:52:36 pm net.sf.ehcache.diskstorepathmanager resolveandlockifneeded warning: diskstorepath 'c:\users\toshiba\appdata\local\temp' used existing cachemanager either in same vm or in different process. diskstore path cachemanager set c:\users\toshiba\appdata\local\temp\ehcache_auto_created3199473242323720768diskstore. avoid warning consider using cachemanager factory methods create singleton cachemanager or specifying separate ehcache configuration (ehcache.xml) each cachemanager instance. 

i in slf4j-api version not match of binding error not error

i saw similar error here ehcache: simple program not working taking distributed cache. code took reference java/ehcache: simple example of use of ehcache 2.6.2

any please why getting error in beginning?

as warning says

to avoid warning consider using cachemanager factory methods create singleton cachemanager or specifying separate ehcache configuration (ehcache.xml) each cachemanager instance. 

the following line using singletonehcacheprovider may fix issue

<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.singletonehcacheprovider</property> 

singletonehcacheprovider


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -