public class MemcachedHttpAsyncCacheStorage extends AbstractBinaryAsyncCacheStorage<net.spy.memcached.CASValue<Object>>
This class is a storage backend that uses an external memcached for storing cached origin responses. This storage option provides a couple of interesting advantages over the default in-memory storage backend:
Note that in a shared memcached pool setting you may wish to make use of the Ketama consistent hashing algorithm to reduce the number of cache misses that might result if one of the memcached cluster members fails (see the KetamaConnectionFactory).
Because memcached places limits on the size of its keys, we need to
introduce a key hashing scheme to map the annotated URLs the higher-level
caching HTTP client wants to use as keys onto ones that are suitable
for use with memcached. Please see KeyHashingScheme
if you would
like to use something other than the provided SHA256KeyHashingScheme
.
Please refer to the memcached documentation and in particular to the documentation for the spymemcached documentation for details about how to set up and configure memcached and the Java client used here, respectively.
Constructor and Description |
---|
MemcachedHttpAsyncCacheStorage(InetSocketAddress address)
Create a storage backend talking to a memcached instance
listening on the specified host and port.
|
MemcachedHttpAsyncCacheStorage(net.spy.memcached.MemcachedClient cache)
Create a storage backend using the pre-configured given
memcached client.
|
MemcachedHttpAsyncCacheStorage(net.spy.memcached.MemcachedClient client,
CacheConfig config,
HttpCacheEntrySerializer<byte[]> serializer,
KeyHashingScheme keyHashingScheme)
Create a storage backend using the given memcached client and
applying the given cache configuration, serialization, and hashing
mechanisms.
|
Modifier and Type | Method and Description |
---|---|
protected org.apache.hc.core5.concurrent.Cancellable |
bulkRestore(Collection<String> storageKeys,
org.apache.hc.core5.concurrent.FutureCallback<Map<String,byte[]>> callback) |
protected org.apache.hc.core5.concurrent.Cancellable |
delete(String storageKey,
org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback) |
protected String |
digestToStorageKey(String key) |
protected org.apache.hc.core5.concurrent.Cancellable |
getForUpdateCAS(String storageKey,
org.apache.hc.core5.concurrent.FutureCallback<net.spy.memcached.CASValue<Object>> callback) |
protected byte[] |
getStorageObject(net.spy.memcached.CASValue<Object> casValue) |
protected org.apache.hc.core5.concurrent.Cancellable |
restore(String storageKey,
org.apache.hc.core5.concurrent.FutureCallback<byte[]> callback) |
protected org.apache.hc.core5.concurrent.Cancellable |
store(String storageKey,
byte[] storageObject,
org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback) |
protected org.apache.hc.core5.concurrent.Cancellable |
updateCAS(String storageKey,
net.spy.memcached.CASValue<Object> casValue,
byte[] storageObject,
org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback) |
getEntries, getEntry, putEntry, removeEntry, updateEntry
public MemcachedHttpAsyncCacheStorage(InetSocketAddress address) throws IOException
address
- where the memcached daemon is runningIOException
- in case of an errorpublic MemcachedHttpAsyncCacheStorage(net.spy.memcached.MemcachedClient cache)
cache
- client to use for communicating with memcachedpublic MemcachedHttpAsyncCacheStorage(net.spy.memcached.MemcachedClient client, CacheConfig config, HttpCacheEntrySerializer<byte[]> serializer, KeyHashingScheme keyHashingScheme)
client
- how to talk to memcachedconfig
- apply HTTP cache-related optionsserializer
- alternative serialization mechanismkeyHashingScheme
- how to map higher-level logical "storage keys"
onto "cache keys" suitable for use with memcachedprotected String digestToStorageKey(String key)
digestToStorageKey
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected byte[] getStorageObject(net.spy.memcached.CASValue<Object> casValue) throws ResourceIOException
getStorageObject
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
ResourceIOException
protected org.apache.hc.core5.concurrent.Cancellable store(String storageKey, byte[] storageObject, org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback)
store
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected org.apache.hc.core5.concurrent.Cancellable restore(String storageKey, org.apache.hc.core5.concurrent.FutureCallback<byte[]> callback)
restore
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected org.apache.hc.core5.concurrent.Cancellable getForUpdateCAS(String storageKey, org.apache.hc.core5.concurrent.FutureCallback<net.spy.memcached.CASValue<Object>> callback)
getForUpdateCAS
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected org.apache.hc.core5.concurrent.Cancellable updateCAS(String storageKey, net.spy.memcached.CASValue<Object> casValue, byte[] storageObject, org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback)
updateCAS
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected org.apache.hc.core5.concurrent.Cancellable delete(String storageKey, org.apache.hc.core5.concurrent.FutureCallback<Boolean> callback)
delete
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
protected org.apache.hc.core5.concurrent.Cancellable bulkRestore(Collection<String> storageKeys, org.apache.hc.core5.concurrent.FutureCallback<Map<String,byte[]>> callback)
bulkRestore
in class AbstractSerializingAsyncCacheStorage<byte[],net.spy.memcached.CASValue<Object>>
Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.