Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Diskcache: Log an error when writing fails #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions diskcache/diskcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down