func()

in groupcache.go [399:430]


func (g *Group) getFromPeer(ctx Context, peer ProtoPeer, key string) (payload, error) {
	req := &pb.GetRequest{
		Group: g.name,
		Key:   key,
	}
	res := &pb.GetResponse{}
	err := peer.Get(ctx, req, res)
	if err != nil {
		return payload{}, err
	}
	value := ByteView{b: res.GetValue()}
	var ttlp *time.Time = nil
	if res.GetTtl() != nil {
		ttl, err := ptypes.Timestamp(res.GetTtl())
		if err != nil {
			return payload{}, err
		}
		ttl = ttl.UTC()
		if ttl.Before(time.Now().UTC()) {
			return payload{}, errResourceExpired
		}
		ttlp = &ttl
	}
	payload := newPayload(value, ttlp)
	// TODO(bradfitz): use res.MinuteQps or something smart to
	// conditionally populate hotCache.  For now just do it some
	// percentage of the time.
	if rand.Intn(populateHotCacheOdds) == 0 {
		g.populateCache(key, payload, &g.hotCache)
	}
	return payload, nil
}