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

Function newCacheWithJanitor

pkg/util/cache/cache.go:1131–1144  ·  view source on GitHub ↗
(de time.Duration, ci time.Duration, m map[string]Item)

Source from the content-addressed store, hash-verified

1129}
1130
1131func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[string]Item) *Cache {
1132 c := newCache(de, m)
1133 // This trick ensures that the janitor goroutine (which--granted it
1134 // was enabled--is running DeleteExpired on c forever) does not keep
1135 // the returned C object from being garbage collected. When it is
1136 // garbage collected, the finalizer stops the janitor goroutine, after
1137 // which c can be collected.
1138 C := &Cache{c}
1139 if ci > 0 {
1140 runJanitor(c, ci)
1141 runtime.SetFinalizer(C, stopJanitor)
1142 }
1143 return C
1144}
1145
1146// New return a new cache with a given default expiration duration and cleanup
1147// interval. If the expiration duration is less than one (or NoExpiration),

Callers 2

NewFunction · 0.85
NewFromFunction · 0.85

Calls 2

newCacheFunction · 0.85
runJanitorFunction · 0.85

Tested by

no test coverage detected