Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jonathanptew opened this issue Sep 13, 2021 · 0 comments

Comments

@jonathanptew
Copy link

jonathanptew commented Sep 13, 2021

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

  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

@jonathanptew jonathanptew changed the title SyncCache<?>.invalidateAll() doesn't seem to work in basic implementation SyncCache<...>.invalidateAll() is not calling/triggering the method annotated with @CacheInvalidate(all = true) Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant