in groupcache.go [576:604]
func (g *Group) putFromPeer(ctx Context, peer ProtoPeer, key string, data []byte, ttl *time.Time) error {
var ttlProto *tspb.Timestamp = nil
var err error
if ttl != nil {
ttlProto, err = ptypes.TimestampProto(*ttl)
if err != nil {
return err
}
}
req := &pb.PutRequest{
Group: g.name,
Key: key,
Value: data,
Ttl: ttlProto,
}
res := &pb.PutResponse{}
err = peer.Put(ctx, req, res)
if err != nil {
return err
}
// 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 {
payload := newPayload(ByteView{b: data}, ttl)
g.populateCache(key, payload, &g.hotCache)
}
return nil
}