代码:

    @Override
@Cacheable(value = CACHE_NAME, key = "'CartItemkey_'+#uId")
public List<String> getCartId(Long uId) {//CartItemkey_1
String key = "CartItemkey_"+uId;
try {
List<String> keyStr = (List<String>) redisCache.get(key, List.class);
logger.info("===========================redis 调用===");
return keyStr;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

出现的原因就:

在第一次调用时候什么都没查到时候   返回 null

其实null 也是一种数据 ,

这时候就被缓存起来了,key:null

所以在你再次调用时候,默认缓存中是有值得,不过这个值是null而已

解决办法:

    @Override
@Cacheable(value = CACHE_NAME, key = "'CartItemkey_'+#uId", unless="#result == null")
public List<String> getCartId(Long uId) {//CartItemkey_1
String key = "CartItemkey_"+uId;
try {
List<String> keyStr = (List<String>) redisCache.get(key, List.class);
logger.info("===========================redis 调用===");
return keyStr;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

Spring 缓存注解@Cacheable 在缓存时候 ,出现了第一次进入调用 方法 ,第二次不调用的异常的更多相关文章

  1. Spring之缓存注解@Cacheable

    https://www.cnblogs.com/fashflying/p/6908028.html https://blog.csdn.net/syani/article/details/522399 ...

  2. 详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用

    https://blog.csdn.net/u012240455/article/details/80844361 注释介绍 @Cacheable @Cacheable 的作用 主要针对方法配置,能够 ...

  3. Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用(转)

    原文地址:https://www.cnblogs.com/fashflying/p/6908028.html 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对 ...

  4. Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用

    从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...

  5. Spring Boot缓存注解@Cacheable、@CacheEvict、@CachePut使用

    从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...

  6. Spring缓存注解@Cacheable

    @Cacheable @Cacheable 的作用 主要针对方法配置,能够根据方法的请求参数对其结果进行缓存 @Cacheable 作用和配置方法 参数 解释 example value 缓存的名称, ...

  7. java spring 使用注解来实现缓存

    这里举例使用spring3.1.4 + ehcache 注解的方式使用cache 是在spring3.1加入的 使用方法: 1.ehcache依赖+spring依赖 <!-- ehcache依赖 ...

  8. 缓存注解@Cacheable、@CacheEvict、@CachePut使用及注解失效时间

    从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...

  9. springboot缓存注解——@Cacheable和@CacheConfig

    @Caching :制定多个缓存规则 @Cacheable 和 @CachePut 同时标注时 ,@CachePut导致还是会走方法跟数据库交互 //根据lastName查,并将结果缓存,并且可以用于 ...

随机推荐

  1. android:numColumns="auto_fit" 失效问题

    GridView 设置此属性无效:android:numColumns="auto_fit" ,请确认已经设置过 android:columnWidth="*dp&quo ...

  2. iOS开发-重写description方法,自定义控制台(log)信息

    description是所有类都有的一个方法. 我们重写这个方法,可以自定义实例输出的信息. 比如我们创建一个Person类: 在.h文件中添加两个属性: #import <Foundation ...

  3. python challenge - map.py

    Hint: K->M    O->Q    E->G everybody thinks twice before solving this. g fmnc wms bgblr rpy ...

  4. asp.net+mvc+easyui+sqlite 简单用户系统学习之旅(三)—— 简单登录页面+sqlite+动软代码生成器的使用

    上一节讲到利用easyui的layout.tree.tab和datagrid创建用户管理的页面,注意利用到easyui的页面一定要按顺序添加jQuery和easyUI的.js和.css样式,灵活查看e ...

  5. Failed to read auto-increment value from storage engine

    今天在使用php artisan db:seed进行填充1000条数据时,出现如下错误Failed to read auto-increment value from storage engine 原 ...

  6. rsync for windows 详细使用教程

    rsync for windows 详细使用教程内容简介:rsync在windows与windows服务器之间的同步设置 1.准备两台机器: server-----192.168.0.201 clie ...

  7. JPA ID生成策略(转---)

    尊重原创:http://tendyming.iteye.com/blog/2024985 JPA ID生成策略 @Table Table用来定义entity主表的name,catalog,schema ...

  8. UML类图详解_泛化关系

    泛化其实就是继承关系,还是比较简单的,那么我们就把之前有些问题的博客UML类图重新来实现一次. 依旧是这个图 下面我们来看一个例子 Account.h #include <cstdlib> ...

  9. Python模块学习之fabric

    fabric是一个运维经常使用到的一个模块.但是我在python3环境下安装fabric就遇到了坑! 安装包名称是fabric3而不是fabric! pip install fabric3 利用fab ...

  10. 使用Crypto++库的CBC模式实现加密

    //***************************************************************************** //@File Name : scsae ...