## org.apache.http.impl.client.cache.memcached
Class MemcachedHttpCacheStorage

    java.lang.Object
      org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage

All Implemented Interfaces:
  HttpCacheStorage

    public class MemcachedHttpCacheStorage

extends Object
implements HttpCacheStorage

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:

1. in-memory cached objects can survive an application restart since they are held in a separate process
2. it becomes possible for several cooperating applications to share a large memcached farm together, effectively providing cache peering of a sort

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).

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.

Since:
  4.1

Constructor Summary
`MemcachedHttpCacheStorage(InetSocketAddress address)` Create a storage backend talking to a memcached instance listening on the specified host and port.
`MemcachedHttpCacheStorage(net.spy.memcached.MemcachedClientIF cache)` Create a storage backend using the pre-configured given memcached client.
`MemcachedHttpCacheStorage(net.spy.memcached.MemcachedClientIF client, CacheConfig config, HttpCacheEntrySerializer serializer)` Create a storage backend using the given memcached client and applying the given cache configuration and cache entry serialization mechanism.

Method Summary
`HttpCacheEntry` `getEntry(String url)` Retrieves the cache entry stored under the given key or null if no entry exists under that key.
`void` `putEntry(String url, HttpCacheEntry entry)` Store a given cache entry under the given key.
`void` `removeEntry(String url)` Deletes/invalidates/removes any cache entries currently stored under the given key.
`void` `updateEntry(String url, HttpCacheUpdateCallback callback)` Atomically applies the given callback to update an existing cache entry under a given key.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MemcachedHttpCacheStorage

    public MemcachedHttpCacheStorage(InetSocketAddress address)
                              throws IOException

  Create a storage backend talking to a memcached instance listening on the specified host and port. This is useful if you just have a single local memcached instance running on the same machine as your application, for example.

  Parameters:
    `address` - where the memcached daemon is running
  Throws:
    `IOException`

### MemcachedHttpCacheStorage

    public MemcachedHttpCacheStorage(net.spy.memcached.MemcachedClientIF cache)

  Create a storage backend using the pre-configured given memcached client.

  Parameters:
    `cache` - client to use for communicating with memcached

### MemcachedHttpCacheStorage

    public MemcachedHttpCacheStorage(net.spy.memcached.MemcachedClientIF client,
                                     CacheConfig config,
                                     HttpCacheEntrySerializer serializer)

  Create a storage backend using the given memcached client and applying the given cache configuration and cache entry serialization mechanism.

  Parameters:
    `client` - how to talk to memcached
    `config` - apply HTTP cache-related options
    `serializer` - how to serialize the cache entries before writing them out to memcached. The provided `DefaultHttpCacheEntrySerializer` is a fine serialization mechanism to use here.

Method Detail

### putEntry

    public void putEntry(String url,
                         HttpCacheEntry entry)
                  throws IOException

  Description copied from interface: `HttpCacheStorage`
  Store a given cache entry under the given key.

  Specified by:
    `putEntry` in interface `HttpCacheStorage`
  Parameters:
    `url` - where in the cache to store the entry
    `entry` - cached response to store
  Throws:
    `IOException`

### getEntry

    public HttpCacheEntry getEntry(String url)
                            throws IOException

  Description copied from interface: `HttpCacheStorage`
  Retrieves the cache entry stored under the given key or null if no entry exists under that key.

  Specified by:
    `getEntry` in interface `HttpCacheStorage`
  Parameters:
    `url` - cache key
  Returns:
    an `HttpCacheEntry` or `null` if no entry exists
  Throws:
    `IOException`

### removeEntry

    public void removeEntry(String url)
                     throws IOException

  Description copied from interface: `HttpCacheStorage`
  Deletes/invalidates/removes any cache entries currently stored under the given key.

  Specified by:
    `removeEntry` in interface `HttpCacheStorage`
  Throws:
    `IOException`

### updateEntry

    public void updateEntry(String url,
                            HttpCacheUpdateCallback callback)
                     throws HttpCacheUpdateException,
                            IOException

  Description copied from interface: `HttpCacheStorage`
  Atomically applies the given callback to update an existing cache entry under a given key.

  Specified by:
    `updateEntry` in interface `HttpCacheStorage`
  Parameters:
    `url` - indicates which entry to modify
    `callback` - performs the update; see `HttpCacheUpdateCallback` for details, but roughly the callback expects to be handed the current entry and will return the new value for the entry.
  Throws:
    `HttpCacheUpdateException`
    `IOException`

Copyright © 1999-2011 The Apache Software Foundation. All Rights Reserved.