c-go cache: Use diskv TempDir to get atomic write

This commit is contained in:
Antoine Pelisse 2017-08-14 15:09:37 -07:00
parent a97a1ba14e
commit e58da7bb7c

View File

@ -19,6 +19,7 @@ package transport
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"path/filepath"
"strings" "strings"
"time" "time"
@ -97,7 +98,10 @@ type authProxyRoundTripper struct {
// response headers and send the If-None-Match header on subsequent // response headers and send the If-None-Match header on subsequent
// corresponding requests. // corresponding requests.
func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper { func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper {
d := diskv.New(diskv.Options{BasePath: cacheDir}) d := diskv.New(diskv.Options{
BasePath: cacheDir,
TempDir: filepath.Join(cacheDir, ".diskv-temp"),
})
t := httpcache.NewTransport(diskcache.NewWithDiskv(d)) t := httpcache.NewTransport(diskcache.NewWithDiskv(d))
t.Transport = rt t.Transport = rt