org.infinispan.util.EntryWrapper Maven / Gradle / Ivy
package org.infinispan.util;
import org.infinispan.Cache;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.entries.ForwardingCacheEntry;
/**
* Wrapper for CacheEntry(s) that can be used to update the cache when it's value is set.
* @param The key type
* @param The value type
*/
public class EntryWrapper extends ForwardingCacheEntry {
private final Cache cache;
private final CacheEntry entry;
/**
* Creates a new entry wrapper given the cache and entry. If the entry is itself an EntryWrapper then the inner
* entry is instead wrapped to prevent double cache.put operations. Also we then we can use the cache given as
* this could have different flags etc.
* @param cache the cache to use on setValue
* @param entry the actual entry
*/
public EntryWrapper(Cache cache, CacheEntry entry) {
this.cache = cache;
// Don't double wrap, but take the most recent
if (entry instanceof EntryWrapper) {
this.entry = ((EntryWrapper) entry).entry;
} else {
this.entry = entry;
}
}
@Override
protected CacheEntry delegate() {
return entry;
}
@Override
public V setValue(V value) {
cache.put(entry.getKey(), value);
return super.setValue(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy