func()

in groupcache.go [541:570]


func (g *Group) store(ctx Context, key string, data []byte, ttl *time.Time) (err error) {
	g.Stats.Stores.Add(1)
	_, err = g.loadGroup.Do(key, func() (interface{}, error) {
		// Deduplication checks - see explanation in load()
		if _, cacheHit := g.lookupCache(key); cacheHit {
			g.Stats.CacheHits.Add(1)
			return nil, nil
		}
		g.Stats.StoresDeduped.Add(1)
		var err error
		if peer, ok := g.peers.PickPeer(key); ok {
			err = g.putFromPeer(ctx, peer, key, data, ttl)
			if err == nil {
				g.Stats.PeerStores.Add(1)
				return nil, nil
			}
			g.Stats.PeerErrors.Add(1)
		}
		err = g.putLocally(ctx, key, data, ttl)
		if err != nil {
			g.Stats.LocalStoreErrs.Add(1)
			return nil, err
		}
		g.Stats.LocalStores.Add(1)
		value := ByteView{b: data}
		g.populateCache(key, newPayload(value, ttl), &g.mainCache)
		return nil, nil
	})
	return
}