MCPcopy Create free account
hub / github.com/patrickmn/go-cache / newCacheWithJanitor

Function newCacheWithJanitor

cache.go:1113–1126  ·  view source on GitHub ↗
(de time.Duration, ci time.Duration, m map[string]Item)

Source from the content-addressed store, hash-verified

1111}
1112
1113func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[string]Item) *Cache {
1114 c := newCache(de, m)
1115 // This trick ensures that the janitor goroutine (which--granted it
1116 // was enabled--is running DeleteExpired on c forever) does not keep
1117 // the returned C object from being garbage collected. When it is
1118 // garbage collected, the finalizer stops the janitor goroutine, after
1119 // which c can be collected.
1120 C := &Cache{c}
1121 if ci > 0 {
1122 runJanitor(c, ci)
1123 runtime.SetFinalizer(C, stopJanitor)
1124 }
1125 return C
1126}
1127
1128// Return a new cache with a given default expiration duration and cleanup
1129// 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…