本文整理汇总了Python中google.appengine.api.memcache.add方法的典型用法代码示例。如果您正苦于以下问题:Python memcache.add方法的具体用法?Python memcache.add怎么用?Python memcache.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.memcache
的用法示例。
在下文中一共展示了memcache.add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xsrf_secret_key
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def xsrf_secret_key():
"""Return the secret key for use for XSRF protection.
If the Site entity does not have a secret key, this method will also create
one and persist it.
Returns:
The secret key.
"""
secret = memcache.get(XSRF_MEMCACHE_ID, namespace=OAUTH2CLIENT_NAMESPACE)
if not secret:
# Load the one and only instance of SiteXsrfSecretKey.
model = SiteXsrfSecretKey.get_or_insert(key_name='site')
if not model.secret:
model.secret = _generate_new_xsrf_secret_key()
model.put()
secret = model.secret
memcache.add(XSRF_MEMCACHE_ID, secret, namespace=OAUTH2CLIENT_NAMESPACE)
return str(secret)
示例2: open_resource
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def open_resource(self, name):
"""Opens a resource from the zoneinfo subdir for reading."""
# Import nested here so we can run setup.py without GAE.
from google.appengine.api import memcache
from pytz import OLSON_VERSION
name_parts = name.lstrip('/').split('/')
if os.path.pardir in name_parts:
raise ValueError('Bad path segment: %r' % os.path.pardir)
cache_key = 'pytz.zoneinfo.%s.%s' % (OLSON_VERSION, name)
zonedata = memcache.get(cache_key)
if zonedata is None:
zonedata = get_zoneinfo().read('zoneinfo/' + '/'.join(name_parts))
memcache.add(cache_key, zonedata)
log.info('Added timezone to memcache: %s' % cache_key)
else:
log.info('Loaded timezone from memcache: %s' % cache_key)
return StringIO(zonedata)
示例3: xsrf_secret_key
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def xsrf_secret_key():
"""Return the secret key for use for XSRF protection.
If the Site entity does not have a secret key, this method will also create
one and persist it.
Returns:
The secret key.
"""
secret = memcache.get(XSRF_MEMCACHE_ID, namespace=OAUTH2CLIENT_NAMESPACE)
if not secret:
# Load the one and only instance of SiteXsrfSecretKey.
model = SiteXsrfSecretKey.get_or_insert(key_name='site')
if not model.secret:
model.secret = _generate_new_xsrf_secret_key()
model.put()
secret = model.secret
memcache.add(XSRF_MEMCACHE_ID, secret,
namespace=OAUTH2CLIENT_NAMESPACE)
return str(secret)
示例4: GetCounterCount
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def GetCounterCount(name):
"""Sums a cumulative value from all the shard counts for the given name.
Args:
name: The name of the counter.
Returns:
Integer; the cumulative count of all sharded counters for the given
counter name.
"""
total = memcache.get(key=name)
if total is not None:
return total
total = 0
all_keys = CounterShardConfig.AllKeys(name)
for counter in ndb.get_multi(all_keys):
if counter is not None:
total += counter.count
if memcache.add(key=name, value=total,
time=_COUNTER_MEMCACHE_EXPIRATION_S):
return total
raise recall_errors.MessageRecallCounterError(
'Unexpected problem adding to memcache: %s.' % name)
示例5: _CacheUserEmailBillingEnabled
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def _CacheUserEmailBillingEnabled(user_email):
"""Cache the user_email to avoid billing-check rountrips.
Wrapped in a separate method to aid error handling.
Args:
user_email: String email address of the form user@domain.com.
Raises:
MessageRecallMemcacheError: If the add fails so cache issues can be noticed.
"""
if not memcache.add(user_email, True, time=_USER_BILLING_CACHE_TIMEOUT_S,
namespace=_APPLICATION_BILLING_CACHE_NAMESPACE):
raise recall_errors.MessageRecallMemcacheError(
'Unexpectedly unable to add application billing information to '
'memcache. Please try again.')
示例6: _CacheUserEmailAsAdmin
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def _CacheUserEmailAsAdmin(user_email):
"""Cache the admin user_email to avoid rountrips.
Wrapped in a separate method to aid error handling.
Args:
user_email: String email address of the form user@domain.com.
Raises:
MessageRecallMemcacheError: If the add fails so cache issues can be noticed.
"""
if not memcache.add(user_email, True, time=_USER_ADMIN_CACHE_TIMEOUT_S,
namespace=_USER_ADMIN_CACHE_NAMESPACE):
raise recall_errors.MessageRecallMemcacheError(
'Unexpectedly unable to add admin user information to memcache. '
'Please try again.')
示例7: count
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def count(self, request):
"""Counts number of tasks in a given state."""
logging.debug('%s', request)
# Check permission.
# If the caller has global permission, it can access all tasks.
# Otherwise, it requires pool dimension to check ACL.
realms.check_tasks_list_acl(request.tags)
if not request.start:
raise endpoints.BadRequestException('start (as epoch) is required')
now = utils.utcnow()
mem_key = self._memcache_key(request, now)
count = memcache.get(mem_key, namespace='tasks_count')
if count is not None:
return swarming_rpcs.TasksCount(count=count, now=now)
try:
count = self._query_from_request(request, 'created_ts').count()
memcache.add(mem_key, count, 24*60*60, namespace='tasks_count')
except ValueError as e:
raise endpoints.BadRequestException(
'Inappropriate filter for tasks/count: %s' % e)
return swarming_rpcs.TasksCount(count=count, now=now)
示例8: start_recording
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def start_recording(env=None):
"""Start recording RPC traces.
This creates a Recorder instance and sets it for the current request
in the global RequestLocalRecorderProxy 'recorder_proxy'.
Args:
env: Optional WSGI environment; defaults to os.environ.
"""
recorder_proxy.clear_for_current_request()
if env is None:
env = os.environ
if not config.should_record(env):
return
if memcache.add(lock_key(), 0,
time=config.LOCK_TIMEOUT, namespace=config.KEY_NAMESPACE):
recorder_proxy.set_for_current_request(Recorder(env))
if config.DEBUG:
logging.debug('Set recorder')
示例9: __init__
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def __init__(self):
# Check if any tasks need to be run
query = _AppEngineUtilities_Cron.all()
query.filter('next_run <= ', datetime.datetime.now())
results = query.fetch(1000)
if len(results) > 0:
one_second = datetime.timedelta(seconds = 1)
before = datetime.datetime.now()
for r in results:
if re.search(':' + APPLICATION_PORT, r.url):
r.url = re.sub(':' + APPLICATION_PORT, ':' + CRON_PORT, r.url)
#result = urlfetch.fetch(r.url)
diff = datetime.datetime.now() - before
if int(diff.seconds) < 1:
if memcache.add(str(r.key), "running"):
result = urlfetch.fetch(r.url)
r.next_run = self._get_next_run(pickle.loads(r.cron_compiled))
r.put()
memcache.delete(str(r.key))
else:
break
示例10: get_count
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def get_count(name):
"""Retrieve the value for a given sharded counter.
Parameters:
name - The name of the counter
"""
total = memcache.get(name, namespace=NAMESPACE)
if total is None:
total = 0
for counter in GeneralCounterShard.all().filter('name = ', name):
total += counter.count
memcache.add(name, str(total), 60, namespace=NAMESPACE)
return total
示例11: add_memcache
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def add_memcache(self, test):
memcache_keyname = self.get_memcache_keyname(test)
memcache.delete(memcache_keyname)
memcache.add(memcache_keyname, self,
settings.STATS_USERTEST_TIMEOUT)
示例12: cached
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def cached(key, func, time=15*60):
# TODO values > 1MB
res = memcache.get(key)
if not res:
res = func()
try:
memcache.add(key, res, time)
except:
pass
return res
示例13: getTeamTotal
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import add [as 别名]
def getTeamTotal(self, team):
self.response.headers['Content-Type'] = 'application/javascript'
key = "TEAM-TOTAL-%s" % team
res = memcache.get(key)
if not res:
total_pledges, total_amount = 0, 0
for pledge in model.Pledge.all().filter("team =", team):
total_pledges += 1
total_amount += pledge.amountCents
# doh, we should probably return a json object here instead of just an
# some ints, but we'd like to be backwards compatible with the previous
# (non-team) api. so for now, let's make use javascript varargs
res = '(%d, %d)' % (total_amount, total_pledges)
memcache.add(key, res, 60)
self.response.write("%s%s" % (self.request.get('callback'), res))