(de time.Duration, ci time.Duration, m map[string]Item)
| 1111 | } |
| 1112 | |
| 1113 | func 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), |
no test coverage detected
searching dependent graphs…