banyehaozi 2014-09-17 03:51 采纳率: 0%
浏览 2187

spring MVC 3.1 ehcache 缓存无效

 <bean id="cacheManagerFactory"
      class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<bean id="cacheManager"  class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory" />
</bean>

我的spring 中配置的ehcache

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">  



<diskStore path="java.io.tmpdir"/>
<defaultCache
   maxElementsInMemory="1000"
   eternal="false"
   timeToIdleSeconds="120"
   timeToLiveSeconds="120"
   overflowToDisk="false"/>
<cache name="theCache"

   maxElementsInMemory="2000"
   eternal="false"
   overflowToDisk="true"
   diskPersistent="true"/>
<cache name="cacheTest"

   maxElementsInMemory="2000"
   eternal="false"
   overflowToDisk="true"
   diskPersistent="true"/>
</ehcache>

ehcache.xml 的配置

下面就是我的service 层

    @Cacheable(value="theCache",key="'customer'")
public Customer GetCustomerByCid(int cid){
    System.out.print("----------------------------------------------------------");
    return cd.GetCustomerByCid(cid);
}

结果 测试点击两次查询tomcat打印:
第一次:
DEBUG - Last-Modified value for [/jxc/customer/GetCustomerByCid] is: -1
----------------------------------------------------------DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@63921a] was not registered for synchronization because synchronization is not active
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [jdbc:mysql://192.168.1.6:3306/lyjxc?useUnicode=true&characterEncoding=utf-8, UserName=root@7-PC, MySQL-AB JDBC Driver] will not be managed by Spring
DEBUG - ooo Using Connection [jdbc:mysql://192.168.1.6:3306/lyjxc?useUnicode=true&characterEncoding=utf-8, UserName=root@7-PC, MySQL-AB JDBC Driver]
DEBUG - ==> Preparing: select * from Customer where cid=?
DEBUG - ==> Parameters: 18(Integer)

第二次:

DEBUG - Last-Modified value for [/jxc/customer/GetCustomerByCid] is: -1
----------------------------------------------------------DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@19cdf24] was not registered for synchronization because synchronization is not active
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [jdbc:mysql://192.168.1.6:3306/lyjxc?useUnicode=true&characterEncoding=utf-8, UserName=root@7-PC, MySQL-AB JDBC Driver] will not be managed by Spring
DEBUG - ooo Using Connection [jdbc:mysql://192.168.1.6:3306/lyjxc?useUnicode=true&characterEncoding=utf-8, UserName=root@7-PC, MySQL-AB JDBC Driver]
DEBUG - ==> Preparing: select * from Customer where cid=?
DEBUG - ==> Parameters: 18(Integer)

很明显是访问了两次数据库,但是 我不知道为什么缓存无效,求大牛指教。。。

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-25 19:35
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog