use of com.google.appengine.api.memcache.MemcacheServiceException in project pratilipi by Pratilipi.
the class MemcacheGaeImpl method putAll.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <K, T extends Serializable> void putAll(Map<K, T> keyValueMap, int expirationDeltaMinutes) {
Map props = new HashMap();
if (expirationDeltaMinutes > 0)
props.put(GCacheFactory.EXPIRATION_DELTA, expirationDeltaMinutes * 60);
for (int i = 0; i < 5; i++) {
if (i > 0) {
try {
long sleepMillis = (long) Math.pow(2, i - 1) * 100;
logger.log(Level.INFO, "Retrying in " + sleepMillis + " milliseconds ...");
Thread.sleep(sleepMillis);
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, "Thread sleep interrupted.", ex);
}
}
try {
Cache cache = CacheManager.getInstance().getCacheFactory().createCache(props);
cache.putAll(keyValueMap);
break;
} catch (GCacheException | MemcacheServiceException ex) {
logger.log(Level.SEVERE, "Failed to update one or more values.", ex);
} catch (CacheException ex) {
logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
}
}
}
use of com.google.appengine.api.memcache.MemcacheServiceException in project pratilipi by Pratilipi.
the class MemcacheGaeImpl method put.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <K, T extends Serializable> void put(K key, T value, int expirationDeltaMinutes) {
Map props = new HashMap();
if (expirationDeltaMinutes > 0)
props.put(GCacheFactory.EXPIRATION_DELTA, expirationDeltaMinutes * 60);
for (int i = 0; i < 5; i++) {
if (i > 0) {
try {
long sleepMillis = (long) Math.pow(2, i - 1) * 100;
logger.log(Level.INFO, "Retrying in " + sleepMillis + " milliseconds ...");
Thread.sleep(sleepMillis);
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, "Thread sleep interrupted.", ex);
}
}
try {
Cache cache = CacheManager.getInstance().getCacheFactory().createCache(props);
cache.put(key, value);
break;
} catch (GCacheException | MemcacheServiceException ex) {
logger.log(Level.SEVERE, "Failed to update value.", ex);
} catch (CacheException ex) {
logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
}
}
}
Aggregations