play.cache.MemcachedImpl Maven / Gradle / Ivy
Show all versions of framework Show documentation
package play.cache;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.transcoders.SerializingTranscoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.apache.commons.lang3.StringUtils.isEmpty;
/**
* Memcached implementation (using http://code.google.com/p/spymemcached/)
*
* expiration is specified in seconds
*/
public class MemcachedImpl implements CacheImpl {
private static final Logger logger = LoggerFactory.getLogger(MemcachedImpl.class);
private final MemcachedClient client;
private final String mdcParameterName;
private final MemcachedTranscoder tc = new MemcachedTranscoder();
public MemcachedImpl(Properties configuration) throws IOException {
System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger");
client = new MemcachedClientBuilder().build(configuration);
mdcParameterName = configuration.getProperty("memcached.mdc.parameter", "");
}
public MemcachedClient getClient() {
return client;
}
@Override
@Nullable
public Object get(@Nonnull String key) {
Future