micronaut-projects / micronaut-projects/micronaut-cache

SyncCache<...>.invalidateAll() is not calling/triggering the method annotated with @CacheInvalidate(all = true)

Open
#360 1 comment 0 reactions 0 assignees View on GitHub
status: awaiting feedback
Dominant language
PLSQL
Stars
32
Forks
36
Avg merge
2h 2m
Merged PRs (30d)
5

Description

### Expected Behavior

```
@Inject
SyncCache 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 cachedItems = new LinkedHashMap<>();
...

@CacheInvalidate(all = true)
public void reset() {
cachedItems.clear();
}
```

### Steps To Reproduce

1. Pull https://github.com/jonathanptew/micronaut-cache-example/
2. Run tests
3. ServiceWithCacheInvalidateResetTest fails on subsequent tests where the size of the cache is > 0
4. 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

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure in ServiceWithCacheInvalidateResetTest from the linked micronaut-cache-example, comparing it with ServiceWithCacheExplictResetTest. Trace SyncCache.invalidateAll() and the @CacheInvalidate(all = true) reset() method to determine why reset() is not triggered. Done means the invalidation path clears cachedItems and the subsequent tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.