SyncCache<...>.invalidateAll() is not calling/triggering the method annotated with @CacheInvalidate(all = true)
Expected Behavior
@Inject
SyncCache<ServiceWithCache> cache;
@BeforeEach
void each() {
cache.invalidateAll();
}
@Test
void singleItemIsCached() {
final var cacheKey = "cacheKey";
assertThat(serviceWithCache.getCacheSize()).isEqualTo(0);
final var cachedValue = serviceWithCache.cachedGet(cacheKey);
...
}
@Test
void multipleItemsAreCached() {
final var items = 5;
final var cacheKey = "cacheKey";
assertThat(serviceWithCache.getCacheSize()).isEqualTo(0);
....
}
In each test I expect that the number of entries in the internal cache object should be 0.
ServiceWithCacheExplictResetTest behaves as expected but doesn't use micronaut's cache invalidation
Actual Behaviour
cache.invalidateAll() doesn't trigger calls to reset()
private final Map<String, String> cachedItems = new LinkedHashMap<>();
...
@CacheInvalidate(all = true)
public void reset() {
cachedItems.clear();
}
Steps To Reproduce
- Pull https://github.com/jonathanptew/micronaut-cache-example/
- Run tests
- ServiceWithCacheInvalidateResetTest fails on subsequent tests where the size of the cache is > 0
- ServiceWithCacheExplictResetTest behaves as expected
Environment Information
❯ mvn --version Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: /usr/local/Cellar/maven/3.8.1 Java version: 16.0.2, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home Default locale: en_NZ, platform encoding: UTF-8 OS name: "mac os x", version: "11.5.2", arch: "x86_64", family: "mac"
Example Application
https://github.com/jonathanptew/micronaut-cache-example/
Version
2.5.13
Can you please confirm that this is still an issue in the latest version of Micronaut?