From 245a83154ebd5e56f5395aff35dc1633b66914dd Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Fri, 18 Jun 2021 16:11:33 -0400 Subject: [PATCH] Diskcache: Log an error when writing fails Currently, writes fail silently. This leads to surprising and very hard to understand cache misses. --- diskcache/diskcache.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/diskcache/diskcache.go b/diskcache/diskcache.go index 42e3129..d71b818 100644 --- a/diskcache/diskcache.go +++ b/diskcache/diskcache.go @@ -7,8 +7,11 @@ import ( "bytes" "crypto/md5" "encoding/hex" - "github.com/peterbourgon/diskv" "io" + + "github.com/peterbourgon/diskv" + + "github.com/sirupsen/logrus" ) // Cache is an implementation of httpcache.Cache that supplements the in-memory map with persistent storage @@ -29,7 +32,9 @@ func (c *Cache) Get(key string) (resp []byte, ok bool) { // Set saves a response to the cache as key func (c *Cache) Set(key string, resp []byte) { key = keyToFilename(key) - c.d.WriteStream(key, bytes.NewReader(resp), true) + if err := c.d.WriteStream(key, bytes.NewReader(resp), true); err != nil { + logrus.WithError(err).WithField("key", key).Error("failed to write cache key to disk") + } } // Delete removes the response with key from the cache