mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-16 06:07:54 +00:00
fix(cache): make in-memory backend Close-able so Shutdown stops its cleaner
cache.Shutdown only called Close() on an io.Closer, which only the Redis backend (CacheWrapper) satisfied -- the in-memory Cache's Shutdown (cancels ctx, stopping its cleanupRoutine background ticker) was never reached, so that goroutine leaked until process exit (and with the default set-up, and whenever Redis is unreachable and EnableCache falls back to memory). Add Close() error to Cache (calls Shutdown, idempotent, leaves the cache usable) so cache.Shutdown handles both backends symmetrically. Update Shutdown doc; add test TestMemoryCacheClose_IdempotentAndStillUsable.
This commit is contained in:
Vendored
+9
@@ -108,6 +108,15 @@ func (c *Cache) Shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
// Close implements io.Closer so the cache layer (cache.Shutdown) can stop the
|
||||
// cleanup goroutine for the in-memory backend, matching the Redis backend
|
||||
// which closes its connection pool. Idempotent: cancelling the context does
|
||||
// not render the cache unusable, it only stops the background cleaner.
|
||||
func (c *Cache) Close() error {
|
||||
c.Shutdown()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) Set(key string, value []byte, ttl time.Duration) {
|
||||
// Calculate the memory size of this entry
|
||||
entrySize := int64(len(key) + len(value) + approxEntryOverhead)
|
||||
|
||||
Reference in New Issue
Block a user