java - Application not geting data from Ehcache for first request -


i trying fetch data cache stored in disk of local path. when first request sent browser not entering cache, instead overriding existing cache (although same data exists in cache) fetching data database.

how can data cache if present not creating new every first request

i invoking cache this

public class servicelistener implements servletcontextlistener { private static final logger log = logger.getlogger(servicelistener.class); public static cachemanager cm;  public void contextdestroyed(servletcontextevent arg0) {  }  public void contextinitialized(servletcontextevent arg0) {     log.info("initialized");     // cachemanager c = cachemanager.newinstance();     cm = cachemanager.getinstance(); } 

}

cache configuration

<ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="ehcache.xsd" updatecheck="true" monitoring="autodetect" dynamicconfig="true"> <diskstore path="/home/teja/projects/main/cacheexp" /> <cache name="cache1" maxentrieslocalheap="10000"     maxentrieslocaldisk="1000" eternal="true" diskspoolbuffersizemb="20"     timetoidleseconds="3000" timetoliveseconds="60000"     diskexpirythreadintervalseconds="150" memorystoreevictionpolicy="lfu"     diskpersistent="true" transactionalmode="off">     <!-- <persistence strategy="localrestartable" /> --> </cache></ehcache> 

sample usage

string key = width + " " + height;             if (!cache.iskeyincache(key)) {                 log.info("entered database");                 list<list> got = support.getdatafromdb(width, height);                 imagelist = got.get(0);                 pricelist = got.get(1);                 seatlist = got.get(2);                 widthlist = got.get(3);                 heightlist = got.get(4);                 cache.put(new element(key, got));             } else {                 log.info("entered cache");                 list got = (list) cache.get(key).getobjectvalue();                 imagelist = (list<string>) got.get(0);                 pricelist = (list<float>) got.get(1);                 seatlist = (list<string>) got.get(2);                 widthlist = (list<integer>) got.get(3);                 heightlist = (list<integer>) got.get(4);             } 

thank you


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -