MCPcopy Index your code
hub / github.com/patrickmn/go-cache / Add

Method Add

cache.go:92–102  ·  view source on GitHub ↗

Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.

(k string, x interface{}, d time.Duration)

Source from the content-addressed store, hash-verified

90// Add an item to the cache only if an item doesn't already exist for the given
91// key, or if the existing item has expired. Returns an error otherwise.
92func (c *cache) Add(k string, x interface{}, d time.Duration) error {
93 c.mu.Lock()
94 _, found := c.get(k)
95 if found {
96 c.mu.Unlock()
97 return fmt.Errorf("Item %s already exists", k)
98 }
99 c.set(k, x, d)
100 c.mu.Unlock()
101 return nil
102}
103
104// Set a new value for the cache key only if it already exists, and the existing
105// item hasn't expired. Returns an error otherwise.

Callers 8

SetMethod · 0.45
setMethod · 0.45
TestAddFunction · 0.45
TestFileSerializationFunction · 0.45

Calls 2

getMethod · 0.95
setMethod · 0.95

Tested by 6

TestAddFunction · 0.36
TestFileSerializationFunction · 0.36