com.google.appengine.api.memcache.MemcacheService.SetPolicy Java Examples

The following examples show how to use com.google.appengine.api.memcache.MemcacheService.SetPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShardedCounter.java    From appengine-modules-sample-java with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the value of this sharded counter.
 *
 * @return Summed total of all shards' counts
 */
public long getCount() {
  final Long value = (Long) mc.get(kind);
  if (value != null) {
    return value;
  }

  long sum = 0;
  final Query query = new Query(kind);
  for (final Entity shard : ds.prepare(query).asIterable()) {
    sum += (Long) shard.getProperty(CounterShard.COUNT);
  }
  mc.put(kind, sum, Expiration.byDeltaSeconds(60),
      SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

  return sum;
}
 
Example #2
Source File: ShardedCounter.java    From appengine-sharded-counters-java with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the value of this sharded counter.
 *
 * @return Summed total of all shards' counts
 */
public final long getCount() {
    Long value = (Long) mc.get(kind);
    if (value != null) {
        return value;
    }

    long sum = 0;
    Query query = new Query(kind);
    for (Entity shard : DS.prepare(query).asIterable()) {
        sum += (Long) shard.getProperty(CounterShard.COUNT);
    }
    mc.put(kind, sum, Expiration.byDeltaSeconds(CACHE_PERIOD),
            SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

    return sum;
}