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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建