From e7163a639a533daca480970ddbf5022e8916f238 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Sun, 7 May 2023 11:04:31 +0800 Subject: [PATCH] fix: mkdirall dir when new file cachego --- file/file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/file/file.go b/file/file.go index 9e84b17..8edd09d 100644 --- a/file/file.go +++ b/file/file.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" - "errors" "fmt" "io/ioutil" "os" @@ -32,6 +31,7 @@ const perm = 0o666 // New creates an instance of File cache func New(dir string) cachego.Cache { + _ = os.MkdirAll(dir, os.ModePerm) return &file{dir: dir} } @@ -100,7 +100,7 @@ func (f *file) Fetch(key string) (string, error) { if f.isExpired(content) { _ = f.Delete(key) - return "", errors.New("cache expired") + return "", cachego.ErrCacheExpired } return content.Data, nil