MCPcopy
hub / github.com/SpecterOps/BloodHound / GuardedSet

Method GuardedSet

packages/go/cache/cache.go:100–111  ·  view source on GitHub ↗

GuardedSet takes a key and a value and sets the value in the cache if it cannot be found. Returns true if value was set, false otherwise. Returns number of bytes written. Returns an error if the underlying cache returns an error during setting the value or if the value couldn't be marshalled.

(key string, value any)

Source from the content-addressed store, hash-verified

98// written. Returns an error if the underlying cache returns an error during setting
99// the value or if the value couldn't be marshalled.
100func (s Cache) GuardedSet(key string, value any) (bool, int, error) {
101 if ok, err := get(s.lru, key, value); err != nil {
102 return false, 0, fmt.Errorf("error checking cache entry exists: %w", err)
103 } else if ok {
104 return false, 0, nil
105 } else {
106 // Currently we don't need to know about evictions with GuardedSet so ignoring
107 // to keep interface sane
108 bytesWritten, _, err := set(s.lru, key, value)
109 return true, bytesWritten, err
110 }
111}
112
113// Len returns the length of the current cache
114func (s Cache) Len() int {

Callers 2

TestCache_GuardedSetFunction · 0.95
cacheQueryResultMethod · 0.80

Calls 3

getFunction · 0.85
setFunction · 0.85
ErrorfMethod · 0.80

Tested by 1

TestCache_GuardedSetFunction · 0.76