@cacheable(「XXX”)时
对象获取XXX (stringa、String b、String c );
spring缓存中使用的key是ESPL表达式,查看源key时,缺省情况下在org.spring framework.cache.interceptor.simple key generator中生成
大于一个参数是最后的方法
/* * generateakeybasedonthespecifiedparameters.*/publicstaticobjectgeneratekey (object. params ) if ) params.lenen ame if(Param!=空! param.getClass ().isArray ) ) {return param; }returnnewsimplekey(Params ); }然后查看org.spring framework.cache.interceptor.simplekey对应的代码,可以看到实际上返回了simple key
/* * * create anew { @ linksimplekey } instance.* @ paramelementstheelementsofthekey */publicsimplekey (object . elemener ) 系统. arraycopy (elements,0,this.params,0,elements.length ); this.hashcode=arrays.deep hashcode (this.params ); 解决想法:
场景1 :编写自定义的密钥生成器并处理相应的密钥。 (上一篇redis的文章已经写好了,所以不重复写)
下面的名为MyKeyGenerator的类
sprintboot使用spring-security包,缓存内存与redis共存
方案2@cacheable(value=「XXX”、key=“xxxx”) ) ) ) ) ) ) ) )。
@cacheevict(value=“XXX”、key=“xxxx”) )
进行适当的key配置
如果是数组,则可以使用key=“#root.args[0]”
参数如下:
名称位置说明示例methodNameroot object当前调用的方法名称#root.methodnamemethodrootobject当前调用的方法# root.method.nametargetrootobject root.targettargetclassrootobject当前调用的目标对象类# root.targetclassargsrootobject当前调用的方法的参数列表# root.arroot cachesroot object当前调用的方法所使用的. nameargumentnameevaluationcontext方法参数的名称可以直接使用#参数名,也可以使用#iban、#a0、# P0 rrram