@classmethod
  def MemcacheWrappedGet(
      cls, key_name, prop_name=None, memcache_secs=MEMCACHE_SECS,
      retry=False):
    """Fetches an entity by key name from model wrapped by Memcache.

    Args:
      key_name: str key name of the entity to fetch.
      prop_name: optional property name to return the value for instead of
        returning the entire entity.
      memcache_secs: int seconds to store in memcache; default MEMCACHE_SECS.
      retry: bool, default False, if this is a retry (2nd attempt) to
        MemcacheWrappedGet the entity.
    Returns:
      If an entity for key_name exists,
        if prop_name == None returns the db.Model entity,
        otherwise only returns the prop_name property value on entity.
      If an entity for key_name does not exist,
        returns None.
    """
    output = None
    if prop_name:
      memcache_key = 'mwgpn_%s_%s_%s' % (cls.kind(), key_name, prop_name)
    else:
      memcache_key = 'mwg_%s_%s' % (cls.kind(), key_name)

    cached = memcache.get(memcache_key)

    if cached is None:
      entity = cls.get_by_key_name(key_name)
      if not entity:
        return

      if prop_name:
        try:
          output = getattr(entity, prop_name)
        except AttributeError:
          logging.error(
              'Retrieving missing property %s on %s',
              prop_name,
              entity.__class__.__name__)
          return
        to_cache = output
      else:
        output = entity
        to_cache = db.model_to_protobuf(entity).SerializeToString()

      try:
        memcache.set(memcache_key, to_cache, memcache_secs)
      except __HOLE__, e:
        logging.warning(
            'MemcacheWrappedGet: failure to memcache.set(%s, ...): %s',
            memcache_key, str(e))
    else:
      if prop_name:
        output = cached
      else:
        try:
          output = db.model_from_protobuf(cached)
        except Exception, e:  # pylint: disable=broad-except
          # NOTE(user): I copied this exception trap style from
          # google.appengine.datastore.datatstore_query.  The notes indicate
          # that trapping this exception by the class itself is problematic
          # due to differences between the Python and SWIG'd exception
          # classes.
          output = None
          memcache.delete(memcache_key)
          if e.__class__.__name__ == 'ProtocolBufferDecodeError':
            logging.warning('Invalid protobuf at key %s', key_name)
          elif retry:
            logging.exception('Unexpected exception in MemcacheWrappedGet')
          if not retry:
            return cls.MemcacheWrappedGet(
                key_name, prop_name=prop_name, memcache_secs=memcache_secs,
                retry=True)
          else:
            return cls.get_by_key_name(key_name)

    return output
dataset/ETHPy150Open google/simian/src/simian/mac/models/base.py/BaseModel.MemcacheWrappedGet