LocalCachedMap should implements RDestroyable. #592

pull/605/head
Nikita 9 years ago
parent 5261be134e
commit 1605d6f9de

@ -170,6 +170,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonExpirable implements R
private RMap<K, V> map;
private Cache<CacheKey, CacheValue> cache;
private int invalidateEntryOnChange;
private int invalidationListenerId;
protected RedissonLocalCachedMap(RedissonClient redisson, CommandAsyncExecutor commandExecutor, String name, LocalCachedMapOptions options) {
super(commandExecutor, name);
@ -198,18 +199,20 @@ public class RedissonLocalCachedMap<K, V> extends RedissonExpirable implements R
}
invalidationTopic = redisson.getTopic(name + ":topic");
invalidationTopic.addListener(new MessageListener<Object>() {
@Override
public void onMessage(String channel, Object msg) {
if (msg instanceof LocalCachedMapClear) {
cache.clear();
}
if (msg instanceof LocalCachedMapInvalidate) {
CacheKey key = new CacheKey(((LocalCachedMapInvalidate)msg).getKeyHash());
cache.remove(key);
if (options.isInvalidateEntryOnChange()) {
invalidationListenerId = invalidationTopic.addListener(new MessageListener<Object>() {
@Override
public void onMessage(String channel, Object msg) {
if (msg instanceof LocalCachedMapClear) {
cache.clear();
}
if (msg instanceof LocalCachedMapInvalidate) {
CacheKey key = new CacheKey(((LocalCachedMapInvalidate)msg).getKeyHash());
cache.remove(key);
}
}
}
});
});
}
}
@Override
@ -359,6 +362,13 @@ public class RedissonLocalCachedMap<K, V> extends RedissonExpirable implements R
Arrays.<Object>asList(getName(), invalidationTopic.getChannelNames().get(0)),
encodedKey, encodedValue, msg, invalidateEntryOnChange);
}
@Override
public void destroy() {
if (invalidationListenerId != 0) {
invalidationTopic.removeListener(invalidationListenerId);
}
}
@Override
public V remove(Object key) {

@ -0,0 +1,15 @@
package org.redisson.api;
/**
*
* @author Nikita Koksharov
*
*/
public interface RDestroyable {
/**
* Allows to destroy object then it's not necessary anymore.
*/
void destroy();
}

@ -28,7 +28,7 @@ import java.util.Map;
* @param <K>
* @param <V>
*/
public interface RLocalCachedMap<K, V> extends Map<K, V>, RExpirable, RLocalCachedMapAsync<K, V> {
public interface RLocalCachedMap<K, V> extends Map<K, V>, RExpirable, RLocalCachedMapAsync<K, V>, RDestroyable {
/**
* Associates the specified <code>value</code> with the specified <code>key</code>.

Loading…
Cancel
Save