Search in sources :

Example 1 with InvalidValueException

use of com.google.appengine.api.memcache.InvalidValueException in project Cached-Datastore by Emperorlou.

the class CachedDatastoreService method incrementStat.

protected double incrementStat(String statKey, double amount) {
    while (true) {
        IdentifiableValue identifiable = mc.getIdentifiable(statKey);
        if (identifiable == null) {
            throw new InvalidValueException("Cannot increment a stat that starts from null.");
        } else {
            double newValue = (((Double) identifiable.getValue()) + amount);
            boolean success = mc.putIfUntouched(statKey, identifiable, newValue);
            if (success)
                return newValue;
        }
    }
}
Also used : InvalidValueException(com.google.appengine.api.memcache.InvalidValueException) IdentifiableValue(com.google.appengine.api.memcache.MemcacheService.IdentifiableValue)

Example 2 with InvalidValueException

use of com.google.appengine.api.memcache.InvalidValueException in project pratilipi by Pratilipi.

the class MemcacheGaeImpl method get.

@SuppressWarnings("unchecked")
@Override
public <K, T extends Serializable> T get(K key) {
    try {
        Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        T value = (T) cache.get(key);
        if (value == null)
            logger.log(Level.INFO, "Cache Miss: " + key);
        // logger.log( Level.INFO, "Cache Hit: " + key );
        return value;
    } catch (InvalidValueException | ClassCastException e) {
        logger.log(Level.SEVERE, "Failed to typecaste cached value to required type.", e);
        return null;
    } catch (CacheException e) {
        logger.log(Level.SEVERE, "Failed to create cache instance.", e);
        return null;
    }
}
Also used : InvalidValueException(com.google.appengine.api.memcache.InvalidValueException) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) CacheException(javax.cache.CacheException) Cache(javax.cache.Cache)

Aggregations

InvalidValueException (com.google.appengine.api.memcache.InvalidValueException)2 IdentifiableValue (com.google.appengine.api.memcache.MemcacheService.IdentifiableValue)1 GCacheException (com.google.appengine.api.memcache.stdimpl.GCacheException)1 Cache (javax.cache.Cache)1 CacheException (javax.cache.CacheException)1