1

On a REST API, I want to create a single endpoint that clears a specific cache:

DELETE /cache/{cacheName}

Is it possible to implement it instead of:

public void clearCache(String cacheName) {
    cacheManager.getCache(cacheName).clear();
}

to something like this?

@CacheRemoveAll
public void clearCache(String cacheName) {}

So I'm avoiding injecting the CacheManager.

anat0lius
  • 2,145
  • 6
  • 33
  • 60

1 Answers1

0

Unfortunatelly, no.

Annotations cannot be configured with dynamic objects, only constants can be used. So it's not possible to pass a path parameter cacheName to @CacheRemoveAll annotation. You can only do that if you know all cache names in advance — by creating a DELETE endpoint for each cache like:

@CacheRemoveAll(cacheName="cache-1")
public void clearCache1(){}

@CacheRemoveAll(cacheName="cache-2")
public void clearCache2(){}
madhead
  • 31,729
  • 16
  • 153
  • 201