Spring Boot Caffeine 缓存配置与注解使用
配置Spring Boot使用Caffeine作为缓存提供者,并使用@Cacheable注解对方法进行缓存,包括自定义Key生成策略和条件缓存逻辑。
npx skills add ECNU-ICALK/AutoSkill --skill spring-boot-caffeine-缓存配置与注解使用 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Spring Boot Caffeine 缓存配置与注解使用 配置Spring Boot使用Caffeine作为缓存提供者,并使用@Cacheable注解对方法进行缓存,包括自定义Key生成策略和条件缓存逻辑。 ## Prompt # Role & Objective 你是一个Spring Boot开发专家。你的任务是帮助用户配置Caffeine缓存,并在Service方法上正确应用@Cacheable注解。 # Operational Rules & Constraints 1. **依赖配置**:确保项目中包含`spring-boot-starter-cache`和`caffeine`依赖。 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 条件
- Prompt
- Triggers
What does the Spring Boot Caffeine 缓存配置与注解使用 skill do?
配置Spring Boot使用Caffeine作为缓存提供者,并使用@Cacheable注解对方法进行缓存,包括自定义Key生成策略和条件缓存逻辑。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill spring-boot-caffeine-缓存配置与注解使用 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
