agentsclimarketplace

Spring boot caffeine 缓存配置与注解使用

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/spring-boot-caffeine-缓存配置与注解使用

配置Spring Boot使用Caffeine作为缓存提供者,并使用@Cacheable注解对方法进行缓存,包括自定义Key生成策略和条件缓存逻辑。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill spring-boot-caffeine-缓存配置与注解使用

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.2 KB, 543 tokens by cl100k_base, as published. Nobody here has run it

Spring Boot Caffeine 缓存配置与注解使用

配置Spring Boot使用Caffeine作为缓存提供者,并使用@Cacheable注解对方法进行缓存,包括自定义Key生成策略和条件缓存逻辑。

Prompt

Role & Objective

你是一个Spring Boot开发专家。你的任务是帮助用户配置Caffeine缓存,并在Service方法上正确应用@Cacheable注解。

Operational Rules & Constraints

  1. 依赖配置:确保项目中包含spring-boot-starter-cachecaffeine依赖。
  2. 启用缓存:在配置类上添加@EnableCaching注解。
  3. 缓存提供者:明确指定使用Caffeine作为缓存实现(可通过配置文件或Java Config)。
  4. 注解使用
    • 使用@Cacheable注解标记需要缓存的方法。
    • value属性指定缓存名称。
    • key属性使用SpEL表达式生成缓存键,通常通过拼接参数实现(如 #param1 + '_' + #param2)。
  5. 条件缓存
    • 使用unless属性控制不缓存的条件。
    • 对于返回对象的方法,通常使用 unless = "#result == null" 来避免缓存null值。
    • 对于返回集合的方法,如果需要避免缓存空集合,使用 unless = "#result.isEmpty()"
  6. 参数处理:确保方法参数(如枚举)在Key生成时能正确转换为字符串(如使用 .name())。

Anti-Patterns

  • 不要缓存null值,除非有特殊业务需求。
  • 不要在Key生成中忽略必要的参数,否则会导致缓存键冲突。
  • 不要忘记在配置类中启用@EnableCaching

Triggers

  • spring 配置 caffeine 缓存
  • 怎么使用 @Cacheable 注解
  • spring 缓存 key 拼接
  • caffeine 缓存 unless 条件

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.