MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Add

Method Add

pkg/util/cache/cache.go:110–120  ·  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

108// Add an item to the cache only if an item doesn't already exist for the given
109// key, or if the existing item has expired. Returns an error otherwise.
110func (c *cache) Add(k string, x interface{}, d time.Duration) error {
111 c.mu.Lock()
112 _, found := c.get(k)
113 if found {
114 c.mu.Unlock()
115 return fmt.Errorf("Item %s already exists", k)
116 }
117 c.set(k, x, d)
118 c.mu.Unlock()
119 return nil
120}
121
122// Set a new value for the cache key only if it already exists, and the existing
123// item hasn't expired. Returns an error otherwise.

Callers 15

ResetContainersMethod · 0.45
increaseIPFunction · 0.45
resourceTaskMethod · 0.45
runtimeTaskMethod · 0.45
runtimeMetricsMethod · 0.45
TestInvokeHandlerFunction · 0.45
TestSendHTTPRequestLoopFunction · 0.45
buildRequestResponseFunction · 0.45
newLogStatStoreFunction · 0.45
TestCoolDownRuntimeFunction · 0.45
TestResetRuntimeFunction · 0.45

Calls 4

getMethod · 0.95
setMethod · 0.95
LockMethod · 0.80
ErrorfMethod · 0.80

Tested by 15

TestInvokeHandlerFunction · 0.36
TestSendHTTPRequestLoopFunction · 0.36
buildRequestResponseFunction · 0.36
TestCoolDownRuntimeFunction · 0.36
TestResetRuntimeFunction · 0.36
initRuntimeFunction · 0.36
TestEventStopFunction · 0.36
TestInvokeDoneFunction · 0.36
TestAddFunction · 0.36