diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-12-10 09:55:41 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-12-10 11:10:41 +0100 |
commit | 3bc6830411be5b60fc6f65f2b64f6bb9973607e0 (patch) | |
tree | 98e9db9fc7aa5451bbf00824ab7851f413340015 /cache | |
parent | e4d6ec94b5c1ea1c670f1e7127fc20ff2371cb0b (diff) | |
download | hugo-3bc6830411be5b60fc6f65f2b64f6bb9973607e0.tar.gz hugo-3bc6830411be5b60fc6f65f2b64f6bb9973607e0.zip |
Remove the retries on error in remote resources.Get
Fixes #9271
See #9259
Diffstat (limited to 'cache')
-rw-r--r-- | cache/filecache/filecache.go | 26 | ||||
-rw-r--r-- | cache/filecache/filecache_config.go | 9 | ||||
-rw-r--r-- | cache/filecache/filecache_test.go | 2 |
3 files changed, 7 insertions, 30 deletions
diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go index 055d34e18..5a87382ae 100644 --- a/cache/filecache/filecache.go +++ b/cache/filecache/filecache.go @@ -48,9 +48,6 @@ type Cache struct { // 0 is effectively turning this cache off. maxAge time.Duration - // Number of retries on create error. - retries int - // When set, we just remove this entire root directory on expiration. pruneAllRootDir string @@ -87,12 +84,11 @@ type ItemInfo struct { } // NewCache creates a new file cache with the given filesystem and max age. -func NewCache(fs afero.Fs, maxAge time.Duration, retries int, pruneAllRootDir string) *Cache { +func NewCache(fs afero.Fs, maxAge time.Duration, pruneAllRootDir string) *Cache { return &Cache{ Fs: fs, nlocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})}, maxAge: maxAge, - retries: retries, pruneAllRootDir: pruneAllRootDir, } } @@ -184,14 +180,7 @@ func (c *Cache) GetOrCreate(id string, create func() (io.ReadCloser, error)) (It err error ) - for i := -1; i < c.retries; i++ { - r, err = create() - if err == nil || c.retries == 0 { - break - } - time.Sleep(1 * time.Second) - } - + r, err = create() if err != nil { return info, nil, err } @@ -227,14 +216,7 @@ func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (Item err error ) - for i := -1; i < c.retries; i++ { - b, err = create() - if err == nil || c.retries == 0 { - break - } - time.Sleep(1 * time.Second) - } - + b, err = create() if err != nil { return info, nil, err } @@ -388,7 +370,7 @@ func NewCaches(p *helpers.PathSpec) (Caches, error) { pruneAllRootDir = "pkg" } - m[k] = NewCache(bfs, v.MaxAge, v.retries, pruneAllRootDir) + m[k] = NewCache(bfs, v.MaxAge, pruneAllRootDir) } return m, nil diff --git a/cache/filecache/filecache_config.go b/cache/filecache/filecache_config.go index 60c25fc4d..816c6b8a6 100644 --- a/cache/filecache/filecache_config.go +++ b/cache/filecache/filecache_config.go @@ -73,9 +73,8 @@ var defaultCacheConfigs = Configs{ Dir: resourcesGenDir, }, cacheKeyGetResource: Config{ - MaxAge: -1, // Never expire - Dir: cacheDirProject, - retries: 3, // Retries on error getting the remote resource. + MaxAge: -1, // Never expire + Dir: cacheDirProject, }, } @@ -91,10 +90,6 @@ type Config struct { // Will resources/_gen will get its own composite filesystem that // also checks any theme. isResourceDir bool - - // Number of retries when errors occurs when creating the element, - // only used for remote resources. - retries int } // GetJSONCache gets the file cache for getJSON. diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go index 6ac36a5c1..6a051a264 100644 --- a/cache/filecache/filecache_test.go +++ b/cache/filecache/filecache_test.go @@ -276,7 +276,7 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) { } } - cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, 0, "") + cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, "") const id = "a32" |