public class MemcachedCache extends Object implements Cache
By default, waits for all memcached commands to complete. However, you can turn this feature off to increase throughput at the cost of allowing for inconsistent cache states.
Note that reset()
(which causes memcached flushing) works only if
you are the sole client of the memcached cluster.
Constructor and Description |
---|
MemcachedCache()
Construction, with single node on the local host, default port 11211
using the binary protocol; waits for completion; no tag prefix.
|
MemcachedCache(MemcachedClient memcached,
boolean waitForCompletion,
boolean soleClient,
String tagPrefix)
Constructor.
|
MemcachedCache(String nodes)
Construction: using the binary protocol; waits for completion; no tag
prefix.
|
MemcachedCache(String nodes,
boolean waitForCompletion,
boolean soleClient,
String tagPrefix)
Construction, with node list, using the binary protocol.
|
Modifier and Type | Method and Description |
---|---|
CacheEntry |
fetch(String key)
Fetches an entry from the cache if it's there and has not yet expired.
|
void |
invalidate(String tag)
Makes sure that all tagged entries are un-fetchable.
|
void |
prune()
Removes expired cache entries.
|
void |
reset()
Removes all entries in the cache.
|
void |
store(String key,
CacheEntry entry)
Stores an entry in the cache.
|
public MemcachedCache() throws IOException
IOException
- In case the memcached client could not be createdpublic MemcachedCache(String nodes) throws IOException
nodes
- The node list (space-separated IP addresses or hostnames with port
specifications after colon)IOException
- In case the memcached client could not be createdpublic MemcachedCache(String nodes, boolean waitForCompletion, boolean soleClient, String tagPrefix) throws IOException
nodes
- The node list (space-separated IP addresses or hostnames with port
specifications after colon)waitForCompletion
- Whether to wait for all commands to be completedsoleClient
- Whether we are the sole clients of the memcached clustertagPrefix
- Prefix to be added to tag keysIOException
- In case the memcached client could not be createdAddrUtil.getAddresses(String)
public MemcachedCache(MemcachedClient memcached, boolean waitForCompletion, boolean soleClient, String tagPrefix)
memcached
- The memcached clientwaitForCompletion
- Whether to wait for all commands to be completedsoleClient
- Whether we are the sole clients of the memcached clustertagPrefix
- Prefix to be added to tag keyspublic void store(String key, CacheEntry entry)
Cache
CacheEntry.getExpirationDate()
, although it may very well
be un-fetchable sooner.
Keys are unique to the cache. Storing for a key that already exists will replace the entry if it exists.
public CacheEntry fetch(String key)
Cache
public void invalidate(String tag)
Cache
invalidate
in interface Cache
tag
- The cache tagpublic void prune()
Cache
Copyright © 2009-2016 Three Crickets LLC.