1

Has anyone tried invalidating an entire memcached namespace?

For example I have two reads methods having differents keys

@Override
@ReadThroughSingleCache(namespace = UrlClientExclusion.TABLE_NAME, expiration = 24 * HOUR)
public List<UrlClientExclusion> list(@ParameterValueKeyProvider String idClient) {

@Override
@ReadThroughSingleCache(namespace = UrlClientExclusion.TABLE_NAME, expiration = 24 * HOUR)
public UrlClientExclusion find(@ParameterValueKeyProvider int idUrlClientExclusion) {

and I want delete entire namespace UrlClientExclusion.TABLE_NAME on update/delete operation

I can't use a keylist method because there are many instances of the app

@InvalidateMultiCache(namespace = UrlClientExclusion.TABLE_NAME)
public int update(UrlClientExclusion urlClientExclusion, /*@ParameterValueKeyProvider List<Object> keylist*/ /* it is impossibile for me put all keys in this list*/) {

so the solution is to delete entire namespace.

What is the annototation to do this? It is possibible to build custom annotation to delete entire namespace? How?

Many thanks

Saša
  • 653
  • 1
  • 5
  • 17
Angelo
  • 814
  • 8
  • 21

2 Answers2

1

I don't know how this can be handled with the simple-spring-memcached lib. But I would suggest you to use Spring's Cache Abstraction instead. In that way you can change a cache storage to one of your preference e.g. ConcurrentHashMap, Ehcache, Redis etc. It would be just a configuration change for your application. For the eviction of the namespace, you could do something like:

@CacheEvict(cacheNames="url_client_exclusion", allEntries=true) 
public int update(...)

Unfortunately there is not an official support for Memcached offered by Pivotal, but if you really need to use Memcached, you could check out Memcached Spring Boot library which is compliant with the Spring Cache Abstraction.

There is a sample Java app where you could see how this lib is used. Over there you could also find an example of @CacheEvict usage (link).

Saša
  • 653
  • 1
  • 5
  • 17
1

Memcached doesn't support namespaces, SSM provides namespaces as a logic abstraction. It is not possible to flush all keys from given namespaces as memcached doesn't group keys into namespaces. Memcached support only flushing/removing single key or all keys.

You can flush all your data from memcached instance or need to provide exact keys that should be removed.

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • I resolve use Spring AOP component. I annotate the method "update" with a custom annotation and create an ASPECT that is executed after the invocation of the annotated method. This aspect is created to flush the cache after the method invocation – Angelo Dec 31 '19 at 09:10
  • Just keep in mind that in case of memcached cache no matter if SSM or Spring Cache/AOP is used there is no support for flushing namespace. Memcached can only flush (remove) single key by name, multiple keys by name or all keys. – ragnor Jan 02 '20 at 05:26