Cleanup removes expired entries from the cache
()
| 56 | |
| 57 | // Cleanup removes expired entries from the cache |
| 58 | func (c *ResponseCache) Cleanup() { |
| 59 | c.mu.Lock() |
| 60 | defer c.mu.Unlock() |
| 61 | |
| 62 | now := time.Now() |
| 63 | for key, entry := range c.cache { |
| 64 | if now.Sub(entry.timestamp) > c.ttl { |
| 65 | delete(c.cache, key) |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // StartCleanupLoop starts a background goroutine to periodically clean up expired entries |
| 71 | func (c *ResponseCache) StartCleanupLoop(interval time.Duration) { |