def get_count(name):
"""Retrieve the value for a given sharded counter.
Args:
name: The name of the counter.
Returns:
Integer; the cumulative count of all sharded counters for the given
counter name.
"""
total = memcache.get(name)
if total is None:
total = 0
all_keys = GeneralCounterShardConfig.all_keys(name)
for counter in ndb.get_multi(all_keys):
if counter is not None:
total += counter.count
memcache.add(name, total, 60)
return total
评论列表
文章目录