org.apache.james.mailbox.caching.guava.GuavaCacheWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apache-james-mailbox-caching
Show all versions of apache-james-mailbox-caching
JAMES-2703 This maven module is deprecated and will be removed straight after upcoming James 3.4.0 release, unless it finds a maintainer.
This module lacks tests and is not used in James products hence the choice to deprecate it.
package org.apache.james.mailbox.caching.guava;
import org.apache.james.mailbox.caching.CacheLoaderFromUnderlying;
import com.google.common.cache.Cache;
public abstract class GuavaCacheWrapper
implements CacheLoaderFromUnderlying {
private final Cache cache;
public GuavaCacheWrapper(Cache cache/*, CacheLoaderFromUnderlying loader*/) {
this.cache = cache;
}
public ValueT get(KeyT key, UnderlyingT underlying) throws ExceptT {
ValueT value = cache.getIfPresent(getKeyRepresentation(key));
if (value != null) {
return value;
} else {
value = load(key, underlying);
if (value != null) {
cache.put(getKeyRepresentation(key), value);
}
return value;
}
}
public void invalidate(KeyT key) {
if (key != null) { //needed?
cache.invalidate(getKeyRepresentation(key));
}
}
public abstract KeyRepresentationT getKeyRepresentation(KeyT key);
}