
org.permians.cache.SpymemcachedCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache-spymemcached Show documentation
Show all versions of cache-spymemcached Show documentation
Implementation of Simple Caching-Interface (using spymemcached)
The newest version!
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;
}
public void set(String pKey, V pObject) throws StorageException {
mMemcachedClient.set(pKey, mExpiration, pObject);
}
public void add(String pKey, V pObject) throws StorageException {
mMemcachedClient.add(pKey, mExpiration, pObject);
}
public void replace(String pKey, V pObject) throws StorageException {
mMemcachedClient.replace(pKey, mExpiration, pObject);
}
@SuppressWarnings("unchecked")
public V get(String pKey) throws RetrievalException {
return (V) mMemcachedClient.get(pKey);
}
public void delete(String pKey) throws StorageException {
mMemcachedClient.delete(pKey);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy