@tasklets.tasklet<EOL><INDENT>def get(self, key, **ctx_options):<DEDENT>
options = _make_ctx_options(ctx_options)<EOL>use_cache = self._use_cache(key, options)<EOL>if use_cache:<EOL><INDENT>self._load_from_cache_if_available(key)<EOL><DEDENT>use_datastore = self._use_datastore(key, options)<EOL>if (use_datastore and<EOL>isinstance(self._conn, datastore_rpc.TransactionalConnection)):<EOL><INDENT>use_memcache = False<EOL><DEDENT>else:<EOL><INDENT>use_memcache = self._use_memcache(key, options)<EOL><DEDENT>ns = key.namespace()<EOL>memcache_deadline = None  <EOL>if use_memcache:<EOL><INDENT>mkey = self._memcache_prefix + key.urlsafe()<EOL>memcache_deadline = self._get_memcache_deadline(options)<EOL>mvalue = yield self.memcache_get(mkey, for_cas=use_datastore,<EOL>namespace=ns, use_cache=True,<EOL>deadline=memcache_deadline)<EOL>if use_cache:<EOL><INDENT>self._load_from_cache_if_available(key)<EOL><DEDENT>if mvalue not in (_LOCKED, None):<EOL><INDENT>cls = model.Model._lookup_model(key.kind(),<EOL>self._conn.adapter.default_model)<EOL>pb = entity_pb.EntityProto()<EOL>try:<EOL><INDENT>pb.MergePartialFromString(mvalue)<EOL><DEDENT>except ProtocolBuffer.ProtocolBufferDecodeError:<EOL><INDENT>logging.warning('<STR_LIT>'<EOL>'<STR_LIT>' % (mkey, ns))<EOL>mvalue = None<EOL><DEDENT>else:<EOL><INDENT>entity = cls._from_pb(pb)<EOL>entity._key = key<EOL>if use_cache:<EOL><INDENT>self._cache[key] = entity<EOL><DEDENT>raise tasklets.Return(entity)<EOL><DEDENT><DEDENT>if mvalue is None and use_datastore:<EOL><INDENT>yield self.memcache_set(mkey, _LOCKED, time=_LOCK_TIME, namespace=ns,<EOL>use_cache=True, deadline=memcache_deadline)<EOL>yield self.memcache_gets(mkey, namespace=ns, use_cache=True,<EOL>deadline=memcache_deadline)<EOL><DEDENT><DEDENT>if not use_datastore:<EOL><INDENT>raise tasklets.Return(None)<EOL><DEDENT>if use_cache:<EOL><INDENT>entity = yield self._get_batcher.add_once(key, options)<EOL><DEDENT>else:<EOL><INDENT>entity = yield self._get_batcher.add(key, options)<EOL><DEDENT>if entity is not None:<EOL><INDENT>if use_memcache and mvalue != _LOCKED:<EOL><INDENT>pbs = entity._to_pb(set_key=False).SerializePartialToString()<EOL>if len(pbs) <= memcache.MAX_VALUE_SIZE:<EOL><INDENT>timeout = self._get_memcache_timeout(key, options)<EOL>yield self.memcache_cas(mkey, pbs, time=timeout, namespace=ns,<EOL>deadline=memcache_deadline)<EOL><DEDENT><DEDENT><DEDENT>if use_cache:<EOL><INDENT>self._cache[key] = entity<EOL><DEDENT>raise tasklets.Return(entity)<EOL>
Return a Model instance given the entity key.

        It will use the context cache if the cache policy for the given
        key is enabled.

        Args:
          key: Key instance.
          **ctx_options: Context options.

        Returns:
          A Model instance if the key exists in the datastore; None otherwise.