org.permians.cache.SpymemcachedCache Maven / Gradle / Ivy
package org.permians.cache;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.List;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.ConnectionFactoryBuilder.Protocol;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.auth.AuthDescriptor;
public class SpymemcachedCache
implements ICache {
public final static int DEFAULT_EXPIRATION_TIME = 60 * 60;
public final static Protocol DEFAULT_PROTOCOL = Protocol.BINARY;
private MemcachedClient mMemcachedClient;
private int mExpiration;
public SpymemcachedCache(List pAddresses)
throws IOException {
this(pAddresses, DEFAULT_PROTOCOL, null, DEFAULT_EXPIRATION_TIME);
}
public SpymemcachedCache(List pAddresses, int pExpiration)
throws IOException {
this(pAddresses, DEFAULT_PROTOCOL, null, pExpiration);
}
public SpymemcachedCache(List pAddresses,
AuthDescriptor pAuth) throws IOException {
this(pAddresses, DEFAULT_PROTOCOL, pAuth, DEFAULT_EXPIRATION_TIME);
}
public SpymemcachedCache(List pAddresses,
AuthDescriptor pAuth, int pExpiration) throws IOException {
this(pAddresses, DEFAULT_PROTOCOL, pAuth, pExpiration);
}
public SpymemcachedCache(List pAddresses,
Protocol pProtocol) throws IOException {
this(pAddresses, pProtocol, null, DEFAULT_EXPIRATION_TIME);
}
public SpymemcachedCache(List pAddresses,
Protocol pProtocol, int pExpiration) throws IOException {
this(pAddresses, pProtocol, null, pExpiration);
}
public SpymemcachedCache(List pAddresses,
Protocol pProtocol, AuthDescriptor pAuth) throws IOException {
this(pAddresses, pProtocol, pAuth, DEFAULT_EXPIRATION_TIME);
}
public SpymemcachedCache(List pAddresses,
Protocol pProtocol, AuthDescriptor pAuth, int pExpiration)
throws IOException {
mExpiration = pExpiration;
mMemcachedClient = new MemcachedClient(new ConnectionFactoryBuilder()
.setProtocol(pProtocol == null ? DEFAULT_PROTOCOL : pProtocol)
.setAuthDescriptor(pAuth).build(), pAddresses);
}
SpymemcachedCache(MemcachedClient pMemcachedClient) {
mExpiration = DEFAULT_EXPIRATION_TIME;
mMemcachedClient = pMemcachedClient;
}
public int getExpiration() {
return mExpiration;
}
public void setExpiration(int pExpiration) {
mExpiration = pExpiration;
}
@Override
public void set(K pKey, V pObject) throws StorageException {
mMemcachedClient.set((String) pKey, mExpiration, pObject);
}
@Override
public void add(K pKey, V pObject) throws StorageException {
mMemcachedClient.add((String) pKey, mExpiration, pObject);
}
@Override
public void replace(K pKey, V pObject) throws StorageException {
mMemcachedClient.replace((String) pKey, mExpiration, pObject);
}
@Override
@SuppressWarnings("unchecked")
public V get(K pKey) throws RetrievalException {
return (V) mMemcachedClient.get((String) pKey);
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy