用的 Spring + Redis 做缓存, 同一个 Service 中, 其他的方法都可以被缓存, 只有某一个方法不可以, 有谁知道为啥么?
8 回复
这是不起作用的那个方法,
/**
* 获取用户最新的健康档案
*
* @param userId 用户Id
* @return
*/
@Cacheable(key = "'userLatestHealthRecord'.concat(#userId)")
public UserHealthRecord userLatestHealthRecord(String userId) {
UserHealthRecord record = this.fetch(Cnd.where("userId", "=", userId).desc("createDate"));
return record;
}
起作用的如下
/**
* 获取该 BMI 分数超过全国用户的百分比
*
* @param score 用户的 bmi 得分
* @return 返回该分数超过全国多少人/%
*/
@Cacheable(key = "'getBmiScorePercent'.concat(#score)")
public int getBmiScorePercent(int score) {
return getScorePercent(score, UserHealthScore.SCORE_TYPE_BMI);
}
Log
2017-01-10 17:14:30.940 TRACE 3940 --- [nio-8080-exec-1] o.s.cache.interceptor.CacheInterceptor : Computed cache key 'userLatestHealthRecordp7pfmo8tm8jptrv3kvsgsku16r' for operation Builder[public com.a.app.model.UserHealthRecord com.a.app.db.service.UserHealthRecordService.userLatestHealthRecord(java.lang.String)] caches=[app_user_health] | key=''userLatestHealthRecord'.concat(#userId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
2017-01-10 17:14:30.941 TRACE 3940 --- [nio-8080-exec-1] o.s.cache.interceptor.CacheInterceptor : No cache entry for key 'userLatestHealthRecordp7pfmo8tm8jptrv3kvsgsku16r' in cache(s) [app_user_health]
2017-01-10 17:14:30.941 TRACE 3940 --- [nio-8080-exec-1] o.s.cache.interceptor.CacheInterceptor : Computed cache key 'userLatestHealthRecordp7pfmo8tm8jptrv3kvsgsku16r' for operation Builder[public com.a.app.model.UserHealthRecord com.a.app.db.service.UserHealthRecordService.userLatestHealthRecord(java.lang.String)] caches=[app_user_health] | key=''userLatestHealthRecord'.concat(#userId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
2017-01-10 17:14:30.992 DEBUG 3940 --- [nio-8080-exec-1] o.nutz.dao.impl.sql.run.NutDaoExecutor : SELECT * FROM user_health_record WHERE user_id=? ORDER BY create_date DESC LIMIT 0, 1
| 1 |
|----------------------------|
| p7pfmo8tm8jptrv3kvsgsku16r |
For example:> "SELECT * FROM user_health_record WHERE user_id='p7pfmo8tm8jptrv3kvsgsku16r' ORDER BY create_date DESC LIMIT 0, 1 "
@wendal 找到点头绪, 将返回类UserHealthRecord
改成其他的就可以, 但是我这个UserHealthRecord
也实现序列化接口了啊, 搞不懂
@wendal 直接返回也不行
@wendal 😢知道为啥了, 因为查出的数据为 null.....
添加回复
请先登陆