(de time.Duration, ci time.Duration, m map[string]Item)
| 1129 | } |
| 1130 | |
| 1131 | func 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), |
no test coverage detected