企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**1. 定义key生成器** ```java @Configuration public class CustomCacheConfig { @Bean("myKeyGenerator") public KeyGenerator keyGenerator() { return new KeyGenerator() { @Override public Object generate(Object target, Method method, Object... params) { //返回的字符串就是key return method.getName() + "[" + Arrays.asList(params).toString() + "]"; } }; } } ``` <br/> **2. 注解中使用自定义key生成器** ```java @Slf4j @Service public class StudentServiceImpl implements StudentService { @Cacheable(value = {"student"}, keyGenerator = "myKeyGenerator") public Student find(Integer id) { Student student = new Student(id, "张三", 25); return student; } } ```