What problem does it solve?
This Skill enables developers to thoroughly test Spring's caching annotations (@Cacheable, @CacheEvict, @CachePut) in isolation, ensuring cache logic functions correctly without requiring a full Spring context or external caching infrastructure.
Core Features & Use Cases
- Test Cache Hit/Miss: Verify that data is cached after the first call and retrieved from the cache on subsequent calls.
- Test Cache Invalidation: Ensure data is removed from the cache when using @CacheEvict.
- Test Cache Updates: Confirm that @CachePut correctly updates the cache with new data.
- Test Conditional Caching: Validate caching behavior based on conditions or when results are null.
- Test Cache Key Generation: Verify that the correct cache keys are generated for different method arguments.
- Use Case: You've implemented caching in your
UserService to improve performance. Use this Skill to write unit tests that confirm a user is fetched from the database only on the first request and from the cache on subsequent requests for the same user ID.
Quick Start
Write a JUnit test to verify that calling getUserById(1L) twice results in the underlying repository being called only once.