本文整理汇总了Python中google.appengine.api.memcache.flush_all方法的典型用法代码示例。如果您正苦于以下问题:Python memcache.flush_all方法的具体用法?Python memcache.flush_all怎么用?Python memcache.flush_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.memcache
的用法示例。
在下文中一共展示了memcache.flush_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetBrowsersDbAndMemcacheUse
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def testGetBrowsersDbAndMemcacheUse(self):
category = 'network'
version_level = 3
cls = result_stats.CategoryBrowserManager
cls.AddUserAgent(category, mock_data.GetUserAgent('Firefox 3.5'))
self.assertEqual(['Firefox 3.5'], cls.GetBrowsers(category, version_level))
# Load browsers from db into memcache and return.
memcache.flush_all()
self.assertEqual(['Firefox 3.5'], cls.GetBrowsers(category, version_level))
# Load browsers memcache (db is not changed).
cls.get_by_key_name(cls.KeyName(category, version_level)).delete()
self.assertEqual(['Firefox 3.5'], cls.GetBrowsers(category, version_level))
# db and memcache are cleared.
memcache.flush_all()
self.assertEqual([], cls.GetBrowsers(category, version_level))
示例2: post
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def post(self):
"""Handle modifying actions and redirect to a GET page."""
if self.request.get('action:flush_memcache'):
if memcache.flush_all():
message = 'Cache flushed, all keys dropped.'
else:
message = 'Flushing the cache failed. Please try again.'
self.redirect(self._construct_url(remove=['action:flush_memcache'],
add={'message': message}))
elif self.request.get('action:delete_entities'):
entity_keys = self.request.params.getall('entity_key')
db.delete(entity_keys)
self.redirect(self._construct_url(
remove=['action:delete_entities'],
add={'message': '%d entities deleted' % len(entity_keys)}))
else:
self.error(404)
示例3: post
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def post(self):
"""Handle modifying actions and redirect to a GET page."""
super(DatastoreRequestHandler, self).post()
if self.request.get('action:flush_memcache'):
if memcache.flush_all():
message = 'Cache flushed, all keys dropped.'
else:
message = 'Flushing the cache failed. Please try again.'
self.redirect(self._construct_url(remove=['action:flush_memcache'],
add={'message': message}))
elif self.request.get('action:delete_entities'):
entity_keys = self.request.params.getall('entity_key')
db.delete(entity_keys)
self.redirect(self._construct_url(
remove=['action:delete_entities'],
add={'message': '%d entities deleted' % len(entity_keys)}))
else:
self.error(404)
示例4: DeleteReposAndTemplateProjects
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def DeleteReposAndTemplateProjects():
"""Delete repos and related template projects."""
user = GetPublicTemplateOwner()
# delete template projects
keys = user.projects
ndb.delete_multi(keys)
# delete ANONYMOUS user
user.key.delete()
# delete code repositories
query = Repo.query(namespace=settings.PLAYGROUND_NAMESPACE)
keys = query.fetch(keys_only=True)
ndb.delete_multi(keys)
# delete repo collections
query = RepoCollection.query(ancestor=GetGlobalRootEntity().key)
keys = query.fetch(keys_only=True)
ndb.delete_multi(keys)
# flush memcache
memcache.flush_all()
示例5: test_get_all_from_memcache
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def test_get_all_from_memcache(self):
template_list = ['template1', 'template2', 'template3']
mem_name = 'template_list'
memcache.set(mem_name, template_list)
template_list_memcache = template_model.Template.get_all()
self.assertLen(template_list_memcache, 2)
memcache.flush_all()
reference_datastore_template_list = template_model.Template.get_all()
self.assertLen(reference_datastore_template_list, 2)
示例6: test_templates
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def test_templates(self):
template = template_model.Template.create(
'loaner_due', title=TEST_TITLE, body=TEST_BODY)
self.assertEqual(template.name, 'loaner_due')
template_model.Template.create('reminder_base', body=TEST_BASE)
template_loader = template_model.Template()
due_date = datetime.datetime(2017, 10, 13, 9, 31, 0, 0)
config_dict = {
'user_email': loanertest.USER_EMAIL,
'serial': '12345ABC',
'day_of_week': due_date.strftime('%A'),
'date': due_date.strftime('%A, %B %d'),
'turtle_name': 'Grumpy'
}
rendered_title, rendered_body = template_loader.render(
'loaner_due', config_dict)
self.assertEqual(rendered_title, 'Your loaner is due on Friday')
self.assertEqual(rendered_body, (
'<html><body>' # Includes the reminder_base template.
'Hello, {}. Your loaner with serial number '
'12345ABC is due on Friday, October 13. Return it by then if you ever '
'want to see your pet turtle, Grumpy, again.'
'</body></html>'.format(loanertest.USER_EMAIL)))
# Without memcache
memcache.flush_all()
rendered_title, rendered_body = template_loader.render(
'loaner_due', config_dict)
self.assertEqual(rendered_title, 'Your loaner is due on Friday')
self.assertEqual(rendered_body, (
'<html><body>'
'Hello, {}. Your loaner with serial number '
'12345ABC is due on Friday, October 13. Return it by then if you ever '
'want to see your pet turtle, Grumpy, again.'
'</body></html>'.format(loanertest.USER_EMAIL)))
示例7: SeedDatastore
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def SeedDatastore(request):
"""Seed Datastore."""
NUM_RECORDS = 1
category = request.GET.get('category')
if category:
test_sets = all_test_sets.GetTestSet(category)
else:
test_sets = all_test_sets.GetVisibleTestSets()
increment_counts = request.GET.get('increment_counts', True)
if increment_counts == '0':
increment_counts = False
def _GetRandomScore(test):
return random.randrange(test.min_value, test.max_value + 1)
for user_agent_string in models.user_agent.TOP_USER_AGENT_STRINGS:
user_agent = models.user_agent.UserAgent.factory(user_agent_string)
logging.info(' - user_agent: %s', user_agent.pretty())
for test_set in test_sets:
logging.info(' -- category: %s', test_set.category)
for user_agent_string in models.user_agent.TOP_USER_AGENT_STRINGS:
logging.info(' ---- browser: %s',
models.user_agent.UserAgent.factory(
user_agent_string).pretty())
for i in range(NUM_RECORDS):
results_str = ','.join(['%s=%s' % (test.key, _GetRandomScore(test))
for test in test_set.tests])
params_str = None
if test_set.default_params:
params_str = str(test_set.default_params)
models.result.ResultParent.AddResult(
test_set, '1.2.3.4', user_agent_string, results_str, params_str)
logging.info(' ------ AddResult, %s of %s: %s',
i + 1, NUM_RECORDS, results_str)
memcache.flush_all()
return http.HttpResponseRedirect('?message=Datastore got seeded.')
示例8: test_retrieve_db_ok
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def test_retrieve_db_ok(self):
"""Assert that content retrieval works for non-memcached DB entities."""
content = 'Isabella, or the Pot of Basil'
namespace = 'default'
request = self.store_request(namespace, content)
embedded = validate(
request.upload_ticket, handlers_endpoints_v1.UPLOAD_MESSAGES[0])
self.call_api('store_inline', message_to_dict(request), 200)
retrieve_request = handlers_endpoints_v1.RetrieveRequest(
digest=embedded['d'], namespace=handlers_endpoints_v1.Namespace())
memcache.flush_all()
response = self.call_api('retrieve', message_to_dict(retrieve_request), 200)
retrieved = response.json
self.assertEqual(content, base64.b64decode(retrieved[u'content']))
示例9: test_assert_task_async_call_rebuld_task_cache_async
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def test_assert_task_async_call_rebuld_task_cache_async(self):
self.assertEqual(0, _assert_bot())
dimensions={
u'id': [u'bot1'],
}
self.mock_now(datetime.datetime(2020, 1, 2, 3, 4, 5))
request1 = _gen_request(properties=_gen_properties(dimensions=dimensions))
task_queues.assert_task_async(request1).get_result()
self.assert_count(1, task_queues.BotDimensions)
self.assert_count(1, task_queues.BotTaskDimensions)
self.assert_count(1, task_queues.TaskDimensions)
bot_root_key = bot_management.get_root_key('bot1')
self.assertEqual(1, len(task_queues.get_queues(bot_root_key)))
# expire BotTaskDimensions by changing time.
memcache.flush_all()
bot_task_dimensions = task_queues.BotTaskDimensions.query(
ancestor=bot_root_key).fetch()[0]
self.mock_now(bot_task_dimensions.valid_until_ts +
datetime.timedelta(seconds=1))
self.assertEqual(0, len(task_queues.get_queues(bot_root_key)))
# request a task with the same dimensions.
memcache.flush_all()
request2 = _gen_request(properties=_gen_properties(dimensions=dimensions))
task_queues.assert_task_async(request2).get_result()
self.assert_count(1, task_queues.BotDimensions)
self.assert_count(1, task_queues.BotTaskDimensions)
self.assert_count(1, task_queues.TaskDimensions)
self.assertEqual(1, len(task_queues.get_queues(bot_root_key)))
示例10: post
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def post(self):
"""Handle POST."""
if self.request.get('flush_memcache'):
if memcache.flush_all():
message = 'Cache flushed, all keys dropped.'
else:
message = 'Flushing the cache failed. Please try again.'
self.redirect_with_message(message)
return
kind = self.request.get('kind')
keys = []
index = 0
num_keys = int(self.request.get('numkeys'))
for i in xrange(1, num_keys+1):
key = self.request.get('key%d' % i)
if key:
keys.append(key)
if self.request.get('action') == 'Delete':
num_deleted = 0
for key in keys:
datastore.Delete(datastore.Key(key))
num_deleted = num_deleted + 1
message = '%d entit%s deleted. %s' % (
num_deleted, ('ies', 'y')[num_deleted == 1], _DATASTORE_CACHING_WARNING)
self.redirect_with_message(message)
return
self.error(404)
示例11: ClearCache
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def ClearCache():
# TODO: determine why the just deleting our keys is insufficient:
# memcache.delete_multi(keys=[_MEMCACHE_KEY_REPO_COLLECTIONS,
# _MEMCACHE_KEY_TEMPLATES])
memcache.flush_all()
示例12: flush_caches
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def flush_caches(*keywords):
"""Flushes the specified set of caches. Pass '*' to flush everything."""
if '*' in keywords or 'resource' in keywords:
resources.clear_caches()
if '*' in keywords or 'memcache' in keywords:
memcache.flush_all()
if '*' in keywords or 'config' in keywords:
config.cache.flush()
for keyword in keywords:
if keyword.startswith('config/'):
config.cache.delete(keyword[7:])
示例13: ClearMemcache
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def ClearMemcache(request):
message = []
continue_url = request.GET.get('continue')
# KABOOM
if request.GET.get('all'):
memcache.flush_all()
message.append('Cleared memcache for all keys.')
# Piecemeal cleanups
else:
recent = request.GET.get('recent')
if recent:
memcache.delete(RECENT_TESTS_MEMCACHE_KEY)
message.append('Cleared memcache for recent tests.')
else:
category = request.GET.get('category')
if category:
categories = category.split(',')
else:
categories = settings.CATEGORIES
browsers = []
ua = request.GET.get('ua')
version_level = request.GET.get('v')
if ua:
browsers = ua.split(',')
logging.info('browsers are: %s' % browsers)
elif not version_level:
return http.HttpResponseBadRequest('Either pass in ua= or v=')
logging.info('categories are: %s' % categories)
for category in categories:
if not browsers:
browsers = result_stats.CategoryBrowserManager.GetBrowsers(
category, version_level)
result_stats.CategoryBrowserManager.DeleteMemcacheValue(
category, version_level)
result_stats.CategoryStatsManager.DeleteMemcacheValues(
category, browsers)
message.append('Cleared memcache for categories: %s and browsers: %s' %
(categories, browsers))
# All done.
if continue_url:
if not re.search('\?', continue_url):
continue_url += '?'
continue_url += '&message=' + urllib.quote(' '.join(message))
return http.HttpResponseRedirect(continue_url)
else:
return http.HttpResponse('<br>'.join(message))
示例14: post
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def post(self):
"""Handle modifying actions and/or redirect to GET page."""
next_param = {}
if self.request.get('action:flush'):
if memcache.flush_all():
next_param['message'] = 'Cache flushed, all keys dropped.'
else:
next_param['message'] = 'Flushing the cache failed. Please try again.'
elif self.request.get('action:display'):
next_param['key'] = self.request.get('key')
elif self.request.get('action:edit'):
next_param['edit'] = self.request.get('key')
elif self.request.get('action:delete'):
key = self.request.get('key')
result = memcache.delete(key)
if result == memcache.DELETE_NETWORK_FAILURE:
next_param['message'] = ('ERROR: Network failure, key "%s" not deleted.'
% key)
elif result == memcache.DELETE_ITEM_MISSING:
next_param['message'] = 'Key "%s" not in cache.' % key
elif result == memcache.DELETE_SUCCESSFUL:
next_param['message'] = 'Key "%s" deleted.' % key
else:
next_param['message'] = ('Unknown return value. Key "%s" might still '
'exist.' % key)
elif self.request.get('action:save'):
key = self.request.get('key')
value = self.request.get('value')
type_ = self.request.get('type')
next_param['key'] = key
try:
if self._set_memcache_value(key, type_, value):
next_param['message'] = 'Key "%s" saved.' % key
else:
next_param['message'] = 'ERROR: Failed to save key "%s".' % key
except ValueError, e:
next_param['message'] = 'ERROR: Unable to encode value: %s' % e
示例15: post
# 需要导入模块: from google.appengine.api import memcache [as 别名]
# 或者: from google.appengine.api.memcache import flush_all [as 别名]
def post(self):
"""Handle modifying actions and/or redirect to GET page."""
super(MemcacheViewerRequestHandler, self).post()
next_param = {}
if self.request.get('action:flush'):
if memcache.flush_all():
next_param['message'] = 'Cache flushed, all keys dropped.'
else:
next_param['message'] = 'Flushing the cache failed. Please try again.'
elif self.request.get('action:display'):
next_param['key'] = self.request.get('key')
elif self.request.get('action:edit'):
next_param['edit'] = self.request.get('key')
elif self.request.get('action:delete'):
key = self.request.get('key')
result = memcache.delete(key)
if result == memcache.DELETE_NETWORK_FAILURE:
next_param['message'] = ('ERROR: Network failure, key "%s" not deleted.'
% key)
elif result == memcache.DELETE_ITEM_MISSING:
next_param['message'] = 'Key "%s" not in cache.' % key
elif result == memcache.DELETE_SUCCESSFUL:
next_param['message'] = 'Key "%s" deleted.' % key
else:
next_param['message'] = ('Unknown return value. Key "%s" might still '
'exist.' % key)
elif self.request.get('action:save'):
key = self.request.get('key')
value = self.request.get('value')
type_ = self.request.get('type')
next_param['key'] = key
converter = self.FRIENDLY_TYPE_NAME_TO_CONVERTER[type_]
try:
memcache_value = converter.to_cache(value)
except ValueError as e:
next_param['message'] = 'ERROR: Failed to save key "%s": %s.' % (key, e)
else:
if self._set_memcache_value(key,
memcache_value,
converter.memcache_type):
next_param['message'] = 'Key "%s" saved.' % key
else:
next_param['message'] = 'ERROR: Failed to save key "%s".' % key
elif self.request.get('action:cancel'):
next_param['key'] = self.request.get('key')
else:
next_param['message'] = 'Unknown action.'
next = self.request.path_url
if next_param:
next = '%s?%s' % (next, self._urlencode(next_param))
self.redirect(next)