功能是用ssh+ehcache做的使用查询缓存后
1)
select * from s where id=1select * from s where id=1select * from s where id=1调用dao层查询方法3次,第二次,第三次是从缓存中查询的。就查了一次数据库。2)
select * from s where id=1select * from s where id=2select * from s where id=3这样就查3次数据库求解决

解决方案 »

  1.   

    先 select * from s然后
    select * from s where id=1select * from s where id=2select * from s where id=3是查询多少次数据库?
      

  2.   

    这种情况我试过了,它只针对sql语句的,这样会执行4次的。没错
      

  3.   

    1)
    select * from s where id=1select * from s where id=1select * from s where id=1
    这样会执行1次查数据库的,缓存开了
      

  4.   

    第一次缓存的select * from s where id=1,是否已经过期了?是否设置了过期时间。。
      

  5.   

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
    monitoring="autodetect">
    <diskStore path="java.io.tmpdir"/>
        <defaultCache
                maxElementsInMemory="10000"
                eternal="false"
                timeToIdleSeconds="300"
                timeToLiveSeconds="180"
                overflowToDisk="true"
                maxElementsOnDisk="10000000"
                diskPersistent="false"
                diskExpiryThreadIntervalSeconds="120"
                memoryStoreEvictionPolicy="LRU"
                />
    <cache name="fileCache"
               maxElementsInMemory="10000"
               maxElementsOnDisk="1000"
               eternal="false"
               overflowToDisk="true"
               diskSpoolBufferSizeMB="20"
               timeToIdleSeconds="300"
               timeToLiveSeconds="180"
               memoryStoreEvictionPolicy="LFU"
                />
    </ehcache>
    你看看这个配置文件不会过期吧?