Python google.appengine.api.memcache.flush_all() Examples

The following are 16 code examples for showing how to use google.appengine.api.memcache.flush_all(). These examples are extracted from open source projects. 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.

You may also want to check out all available functions/classes of the module google.appengine.api.memcache , or try the search function .

Example 1
Project: browserscope   Author: elsigh   File: test_result_stats.py    License: Apache License 2.0 6 votes vote down vote up
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)) 
Example 2
Project: browserscope   Author: elsigh   File: datastore_viewer.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 3
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: datastore_viewer.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 4
Project: cloud-playground   Author: googlearchive   File: model.py    License: Apache License 2.0 6 votes vote down vote up
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() 
Example 5
Project: loaner   Author: google   File: template_model_test.py    License: Apache License 2.0 5 votes vote down vote up
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) 
Example 6
Project: loaner   Author: google   File: template_model_test.py    License: Apache License 2.0 5 votes vote down vote up
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))) 
Example 7
Project: browserscope   Author: elsigh   File: util.py    License: Apache License 2.0 5 votes vote down vote up
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.') 
Example 8
Project: luci-py   Author: luci   File: handlers_endpoints_v1_test.py    License: Apache License 2.0 5 votes vote down vote up
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'])) 
Example 9
Project: luci-py   Author: luci   File: task_queues_test.py    License: Apache License 2.0 5 votes vote down vote up
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))) 
Example 10
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
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) 
Example 11
Project: cloud-playground   Author: googlearchive   File: templates.py    License: Apache License 2.0 5 votes vote down vote up
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() 
Example 12
Project: personfinder   Author: google   File: main.py    License: Apache License 2.0 5 votes vote down vote up
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:]) 
Example 13
Project: browserscope   Author: elsigh   File: util.py    License: Apache License 2.0 4 votes vote down vote up
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)) 
Example 14
Project: browserscope   Author: elsigh   File: memcache_viewer.py    License: Apache License 2.0 4 votes vote down vote up
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 
Example 15
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: memcache_viewer.py    License: Apache License 2.0 4 votes vote down vote up
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) 
Example 16
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 4 votes vote down vote up
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._SetValue(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