cleanupLoop periodically cleans up expired items.
()
| 198 | |
| 199 | // cleanupLoop periodically cleans up expired items. |
| 200 | func (c *Cache) cleanupLoop() { |
| 201 | ticker := time.NewTicker(c.config.CleanupInterval) |
| 202 | defer func() { |
| 203 | ticker.Stop() |
| 204 | close(c.closedChan) |
| 205 | }() |
| 206 | |
| 207 | for { |
| 208 | select { |
| 209 | case <-ticker.C: |
| 210 | c.cleanup() |
| 211 | case <-c.stopChan: |
| 212 | return |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // cleanup removes expired items. |
| 218 | func (c *Cache) cleanup() { |