Example usage for org.apache.http.impl.client.cache.memcached MemcachedOperationTimeoutException MemcachedOperationTimeoutException

List of usage examples for org.apache.http.impl.client.cache.memcached MemcachedOperationTimeoutException MemcachedOperationTimeoutException

Introduction

In this page you can find the example usage for org.apache.http.impl.client.cache.memcached MemcachedOperationTimeoutException MemcachedOperationTimeoutException.

Prototype

public MemcachedOperationTimeoutException(final Throwable cause) 

Source Link

Usage

From source file:org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage.java

public void putEntry(final String url, final HttpCacheEntry entry) throws IOException {
    final byte[] bytes = serializeEntry(url, entry);
    final String key = getCacheKey(url);
    if (key == null) {
        return;/*w  w w. j av  a 2s . c  o m*/
    }
    try {
        client.set(key, 0, bytes);
    } catch (final OperationTimeoutException ex) {
        throw new MemcachedOperationTimeoutException(ex);
    }
}

From source file:org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage.java

public HttpCacheEntry getEntry(final String url) throws IOException {
    final String key = getCacheKey(url);
    if (key == null) {
        return null;
    }// ww w . j av  a  2s  .c om
    try {
        final MemcachedCacheEntry mce = reconstituteEntry(client.get(key));
        if (mce == null || !url.equals(mce.getStorageKey())) {
            return null;
        }
        return mce.getHttpCacheEntry();
    } catch (final OperationTimeoutException ex) {
        throw new MemcachedOperationTimeoutException(ex);
    }
}

From source file:org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage.java

public void removeEntry(final String url) throws IOException {
    final String key = getCacheKey(url);
    if (key == null) {
        return;/*from   w w  w.jav  a2s  .c o  m*/
    }
    try {
        client.delete(key);
    } catch (final OperationTimeoutException ex) {
        throw new MemcachedOperationTimeoutException(ex);
    }
}

From source file:org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage.java

public void updateEntry(final String url, final HttpCacheUpdateCallback callback)
        throws HttpCacheUpdateException, IOException {
    int numRetries = 0;
    final String key = getCacheKey(url);
    if (key == null) {
        throw new HttpCacheUpdateException("couldn't generate cache key");
    }//w  ww .j av  a 2 s. c o m
    do {
        try {
            final CASValue<Object> v = client.gets(key);
            MemcachedCacheEntry mce = (v == null) ? null : reconstituteEntry(v.getValue());
            if (mce != null && (!url.equals(mce.getStorageKey()))) {
                mce = null;
            }
            final HttpCacheEntry existingEntry = (mce == null) ? null : mce.getHttpCacheEntry();
            final HttpCacheEntry updatedEntry = callback.update(existingEntry);

            if (existingEntry == null) {
                putEntry(url, updatedEntry);
                return;

            } else {
                final byte[] updatedBytes = serializeEntry(url, updatedEntry);
                final CASResponse casResult = client.cas(key, v.getCas(), updatedBytes);
                if (casResult != CASResponse.OK) {
                    numRetries++;
                } else {
                    return;
                }
            }
        } catch (final OperationTimeoutException ex) {
            throw new MemcachedOperationTimeoutException(ex);
        }
    } while (numRetries <= maxUpdateRetries);

    throw new HttpCacheUpdateException("Failed to update");
}