Hi all,
I would like to make an interceptor for a certain cache, but as I know, the
CacheInterceptor is worked for all the caches.
I can filter it with a cache name like the code as bellow, and my questions are
is it efficiently? and any other choice?
private static class Interceptor implements CacheInterceptor<Object, Object> {
private final Integer key; // condition for key
private String cache_name; // filter for cache's name
Interceptor(Integer key, String cache_name) {
this.key = key;
this.cache_name = cache_name;
}
/** {@inheritDoc} */
@Nullable
@Override
public Object onBeforePut(Cache.Entry entry, Object newVal) {
System.out.println("Interceptor onBeforePut");
System.out.println(entry);
// filter by the cache name.
if (!((CacheLazyEntry)entry).getCacheName().equals(cache_name))
{
System.out.println("Ignore the cache " +
((CacheLazyEntry)entry).getCacheName());
return newVal;
} .... }}Thanks very much.
Regards,
Lin Lyu