Ehcache缓存注解不起作用。

乐之者v 2018-03-29 09:58:26
我在SpringBoot里面配置Ehcache,不知道为什么,没起作用。
UserDao文件如下:

@CacheConfig
public interface UserDao {
@Cacheable( cacheNames = "users" )
User selectByPrimaryKey(String uid);
}

UserService文件如下:

public interface UserSerevice {
public User showUsers(String uid);

}

UserServiceImp文件如下:

@Service
public class UserServiceImp implements UserSerevice {
@Autowired
private UserDao userDao;

@Override
public User showUsers(String uid){
return userDao.selectByPrimaryKey(uid);
}
}


ehcache.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<diskStore path="java.io.tmpdir/Tmp_EhCache" />
<defaultCache
eternal="false"
maxElementsInMemory="1000"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LRU" />
<cache name="users"
maxEntriesLocalHeap="200"
timeToLiveSeconds="600">
</cache>
</ehcache>

这个是application.yml配置文件。。

spring:
datasource:
url: jdbc:mysql://localhost:3306/shiro
username: root
password: root
thymeleaf:
cache: true
check-template-location: true
content-type: text/html
enabled: true
encoding: utf-8
mode: HTML5
prefix: classpath:/templates/
suffix: .html
cache:
ehcache:
config: classpath:/ehcache.xml
debug:
true
mybatis:
mapper-locations: classpath:/mapping/*Mapper.xml
# 打印sql
logging:
level:
com.example.demo.dao : debug


不知道为什么,第一次查询的时候,打印了mybatis的sql日志,第二遍的时候还是打印了sql。。
如果缓存起作用的话,是不是第二遍就不会打印sql了?
我加入CacheManager调试,发现确实存在users缓存。。但是缓存里面好像没有数据。。
我把缓存注解,从dao层调到Service层,也还是不行。。
...全文
384 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧