本文整理汇总了Python中google.appengine.api.memcache.set方法的典型用法代码示例。如果您正苦于以下问题:Python memcache.set方法的具体用法?Python memcache.set怎么用?Python memcache.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.memcache
的用法示例。
在下文中一共展示了memcache.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GvizTableData
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def GvizTableData(request):
"""Returns a string formatted for consumption by a Google Viz table."""
#def throw_deadline():
# logging.info('MANUAL THROW!! DeadlineExceededError DeadlineExceededError')
# raise DeadlineExceededError
#t = Timer(15.0, throw_deadline)
test_set = None
category = request.GET.get('category')
if not category:
return http.HttpResponseBadRequest('Must pass category=something')
test_set = all_test_sets.GetTestSet(category)
if not test_set:
return http.HttpResponseBadRequest(
'No test set was found for category=%s' % category)
formatted_gviz_table_data = GetStats(request, test_set, 'gviz_table_data')
return http.HttpResponse(formatted_gviz_table_data)
示例2: _get_memcache_value_and_type
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def _get_memcache_value_and_type(self, key):
"""Fetch value from memcache and detect its type.
Args:
key: String
Returns:
(value, type), value is a Python object or None if the key was not set in
the cache, type is a string describing the type of the value.
"""
try:
value = memcache.get(key)
except (pickle.UnpicklingError, AttributeError, EOFError, ImportError,
IndexError), e:
# Pickled data could be broken or the user might have stored custom class
# instances in the cache (which can't be unpickled from here).
msg = 'Failed to retrieve value from cache: %s' % e
return msg, 'error'
示例3: _set_memcache_value
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def _set_memcache_value(self, key, type_, value):
"""Convert a string value and store the result in memcache.
Args:
key: String
type_: String, describing what type the value should have in the cache.
value: String, will be converted according to type_.
Returns:
Result of memcache.set(key, converted_value). True if value was set.
Raises:
ValueError: Value can't be converted according to type_.
"""
for _, converter, typestr in self.TYPES:
if typestr == type_:
value = converter(value)
break
else:
raise ValueError('Type %s not supported.' % type_)
return memcache.set(key, value)
示例4: get
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def get(self):
util.EnableCors(self)
WP_PLEDGES = 4099
VERSION_12_AND_UNDER = 59009
count = memcache.get('TOTAL-PLEDGES')
if not count:
query = model.Pledge.all(keys_only=True).filter('model_version >', 12)
i = 0
while True:
result = query.fetch(1000)
i = i + len(result)
if len(result) < 1000:
break
cursor = query.cursor()
query.with_cursor(cursor)
count = i + WP_PLEDGES + VERSION_12_AND_UNDER
memcache.set('TOTAL-PLEDGES', count, 120)
self.response.headers['Content-Type'] = 'application/json'
json.dump({'count':count}, self.response)
示例5: update
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def update(cls, domain, time=0):
"""
Updates the memcached stats for a given domain
This is used when a report is updated so that memcached
has the current stats.
Args:
domain - str - The domain to use for the namespace
time - int - The timeout for stored keys (default: 5 seconds)
"""
namespace = "{}|{}".format('stats', domain)
for status in VALID_STATUSES:
count = EmailReport.query(EmailReport.reported_domain == domain,
EmailReport.status == status).count()
memcache.set(
key=status, namespace=namespace, value=count, time=time)
示例6: _update_memcached
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def _update_memcached(cls, domain, time=3600 * 24, records=None):
"""
Updates memcached with the latest data from the datastore
and returns that data. By default stores entries to expire after
24 hours.
"""
namespace = "{}|".format(domain)
if not records:
records = cls._get_from_datastore(domain,
cls._memcache_date_offset)
memcache.set(
key=cls._memcache_key,
namespace=namespace,
value=json.dumps(records),
time=time)
return records
示例7: get_by_sid
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def get_by_sid(cls, sid):
"""Returns a ``Session`` instance by session id.
:param sid:
A session id.
:returns:
An existing ``Session`` entity.
"""
data = memcache.get(sid)
if not data:
session = model.Key(cls, sid).get()
if session:
data = session.data
memcache.set(sid, data)
return data
示例8: GetUserAccessToken
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def GetUserAccessToken(user_email, force_refresh=False):
"""Helper to get a refreshed access_token for a user via service account.
Args:
user_email: User email for which access_token will be retrieved.
force_refresh: Boolean, if True force a token refresh.
Returns:
Cached access_token or a new one.
"""
access_token = memcache.get(user_email, namespace=_CACHE_NAMESPACE)
if access_token and not force_refresh:
return access_token
credentials = _GetSignedJwtAssertionCredentials(user_email)
# Have observed the following error from refresh():
# 'Unable to fetch URL: https://accounts.google.com/o/oauth2/token'
_LOG.debug('Refreshing access token for %s.', user_email)
credentials.refresh(http_utils.GetHttpObject())
access_token = credentials.access_token
if memcache.set(user_email, access_token, time=_ACCESS_TOKEN_CACHE_S,
namespace=_CACHE_NAMESPACE):
return access_token
raise recall_errors.MessageRecallCounterError(
'Exceeded retry limit in GetUserAccessToken: %s.' % user_email)
示例9: add_values
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def add_values():
# [START add_values]
# Add a value if it doesn't exist in the cache
# with a cache expiration of 1 hour.
memcache.add(key="weather_USA_98105", value="raining", time=3600)
# Set several values, overwriting any existing values for these keys.
memcache.set_multi(
{"USA_98115": "cloudy", "USA_94105": "foggy", "USA_94043": "sunny"},
key_prefix="weather_",
time=3600
)
# Atomically increment an integer value.
memcache.set(key="counter", value=0)
memcache.incr("counter")
memcache.incr("counter")
memcache.incr("counter")
# [END add_values]
示例10: get_content
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def get_content(namespace, hash_key):
"""Returns the content from either memcache or datastore, when stored inline.
This does NOT return data from GCS, it is up to the client to do that.
Returns:
tuple(content, ContentEntry)
At most only one of the two is set.
Raises LookupError if the content cannot be found.
Raises ValueError if the hash_key is invalid.
"""
memcache_entry = memcache.get(hash_key, namespace='table_%s' % namespace)
if memcache_entry is not None:
return (memcache_entry, None)
else:
# Raises ValueError
key = get_entry_key(namespace, hash_key)
entity = key.get()
if entity is None:
raise LookupError("namespace %s, key %s does not refer to anything" %
(namespace, hash_key))
return (entity.content, entity)
示例11: get_task_queue_host
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def get_task_queue_host():
"""Returns domain name of app engine instance to run a task queue task on.
By default will use 'backend' module. Can be changed by calling
set_task_queue_module during application startup.
This domain name points to a matching version of appropriate app engine
module - <version>.<module>.<app-id>.appspot.com where:
version: version of the module that is calling this function.
module: app engine module to execute task on.
That way a task enqueued from version 'A' of default module would be executed
on same version 'A' of backend module.
"""
# modules.get_hostname sometimes fails with unknown internal error.
# Cache its result in a memcache to avoid calling it too often.
cache_key = 'task_queue_host:%s:%s' % (_task_queue_module, get_app_version())
value = gae_memcache.get(cache_key)
if not value:
value = modules.get_hostname(module=_task_queue_module)
gae_memcache.set(cache_key, value)
return value
示例12: get_bot_version
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def get_bot_version(host):
"""Retrieves the current bot version (SHA256) loaded on this server.
The memcache is first checked for the version, otherwise the value
is generated and then stored in the memcache.
Returns:
tuple(hash of the current bot version, dict of additional files).
"""
signature = _get_signature(host)
version = memcache.get('version-' + signature, namespace='bot_code')
if version:
return version, None
# Need to calculate it.
additionals = {'config/bot_config.py': get_bot_config().content}
bot_dir = os.path.join(ROOT_DIR, 'swarming_bot')
version = bot_archive.get_swarming_bot_version(
bot_dir, host, utils.get_app_version(), additionals,
local_config.settings())
memcache.set('version-' + signature, version, namespace='bot_code', time=60)
return version, additionals
示例13: _pre_put_hook
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def _pre_put_hook(self):
super(TaskDimensions, self)._pre_put_hook()
sets = set()
for s in self.sets:
s._pre_put_hook()
sets.add('\000'.join(s.dimensions_flat))
if len(sets) != len(self.sets):
# Make sure there's no duplicate TaskDimensionsSet.
raise datastore_errors.BadValueError(
'%s.sets must all be unique' % self.__class__.__name__)
### Private APIs.
# Limit in rebuild_task_cache_async. Meant to be overridden in unit test.
示例14: assert_task_async
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def assert_task_async(request):
"""Makes sure the TaskRequest dimensions, for each TaskProperties, are listed
as a known queue.
This function must be called before storing the TaskRequest in the DB.
When a cache miss occurs, a task queue is triggered.
Warning: the task will not be run until the task queue ran, which causes a
user visible delay. There is no SLA but expected range is normally seconds at
worst. This only occurs on new kind of requests, which is not that often in
practice.
"""
# It's important that the TaskRequest to not be stored in the DB yet, still
# its key could be set.
exp_ts = request.created_ts
futures = []
for i in range(request.num_task_slices):
t = request.task_slice(i)
exp_ts += datetime.timedelta(seconds=t.expiration_secs)
futures.append(_assert_task_props_async(t.properties, exp_ts))
for f in futures:
yield f
示例15: import_config_set
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import set [as 别名]
def import_config_set(config_set):
"""Imports a config set."""
import_attempt_metric.increment(fields={'config_set': config_set})
service_match = config.SERVICE_CONFIG_SET_RGX.match(config_set)
if service_match:
service_id = service_match.group(1)
return import_service(service_id)
project_match = config.PROJECT_CONFIG_SET_RGX.match(config_set)
if project_match:
project_id = project_match.group(1)
return import_project(project_id)
ref_match = config.REF_CONFIG_SET_RGX.match(config_set)
if ref_match:
project_id = ref_match.group(1)
ref_name = ref_match.group(2)
return import_ref(project_id, ref_name)
raise ValueError('Invalid config set "%s' % config_set)
## A cron job that schedules an import push task for each config set