MCPcopy
hub / github.com/dgraph-io/dgraph / SetIfAbsent

Method SetIfAbsent

posting/lists.go:248–256  ·  view source on GitHub ↗

SetIfAbsent adds the list for the specified key to the cache. If a list for the same key already exists, the cache will not be modified and the existing list will be returned instead. This behavior is meant to prevent the goroutines using the cache from ending up with an orphaned version of a list.

(key string, updated *List)

Source from the content-addressed store, hash-verified

246// will be returned instead. This behavior is meant to prevent the goroutines
247// using the cache from ending up with an orphaned version of a list.
248func (lc *LocalCache) SetIfAbsent(key string, updated *List) *List {
249 lc.Lock()
250 defer lc.Unlock()
251 if pl, ok := lc.plists[key]; ok {
252 return pl
253 }
254 lc.plists[key] = updated
255 return updated
256}
257
258func (lc *LocalCache) getInternal(key []byte, readFromDisk, readUids bool) (*List, error) {
259 skey := string(key)

Callers 5

getInternalMethod · 0.95
rebuildListTypeFunction · 0.80
BenchmarkTestCacheFunction · 0.80
addMutationFunction · 0.80
StoreMethod · 0.80

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by 2

BenchmarkTestCacheFunction · 0.64
addMutationFunction · 0.64