def _Dynamic_GrabTail(self, request, response):
    if request.item_count() <= 0:
      return

    namespace = request.name_space()

    if not namespace:
      return

    namespace_dict = self._the_cache.get(namespace, None)
    if namespace_dict is None:
      return

    items = namespace_dict.items()
    items.sort(None, lambda (key, entry): entry.created_time)

    item_count = 0
    for (key, entry) in items:
      if entry.CheckExpired():
        del namespace_dict[key]
      elif not entry.CheckLocked():
        del namespace_dict[key]
        item = response.add_item()
        item.set_value(entry.value)
        item.set_flags(entry.flags)
        item_count += 1
        self._hits += 1
        self._byte_hits += len(entry.value)
        if item_count == request.item_count():
          return
Implementation of MemcacheService::GrabTail().
dataset/ETHPy150Open CollabQ/CollabQ/.google_appengine/google/appengine/api/memcache/memcache_stub.py/MemcacheServiceStub._Dynamic_GrabTail