summaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorPaul van Brouwershaven <vanbroup@users.noreply.github.com>2021-12-02 12:56:25 +0100
committerGitHub <noreply@github.com>2021-12-02 12:56:25 +0100
commit66753416b5ec0f9f1be588a935d5551dfb5eebb9 (patch)
tree2541d5a3630a7aba3315c627d458e54b4812408a /cache
parent133e4bfbeee47bf6843fbcad90f14501f3d3a099 (diff)
Make resources.Get use a file cache for remote resources
Closes #9228
Diffstat (limited to 'cache')
-rw-r--r--cache/filecache/filecache_config.go17
-rw-r--r--cache/filecache/filecache_config_test.go16
2 files changed, 23 insertions, 10 deletions
diff --git a/cache/filecache/filecache_config.go b/cache/filecache/filecache_config.go
index 801799e36..1b3819771 100644
--- a/cache/filecache/filecache_config.go
+++ b/cache/filecache/filecache_config.go
@@ -42,11 +42,12 @@ var defaultCacheConfig = Config{
}
const (
- cacheKeyGetJSON = "getjson"
- cacheKeyGetCSV = "getcsv"
- cacheKeyImages = "images"
- cacheKeyAssets = "assets"
- cacheKeyModules = "modules"
+ cacheKeyGetJSON = "getjson"
+ cacheKeyGetCSV = "getcsv"
+ cacheKeyImages = "images"
+ cacheKeyAssets = "assets"
+ cacheKeyModules = "modules"
+ cacheGetResource = "getresource"
)
type Configs map[string]Config
@@ -70,6 +71,7 @@ var defaultCacheConfigs = Configs{
MaxAge: -1,
Dir: resourcesGenDir,
},
+ cacheGetResource: defaultCacheConfig,
}
type Config struct {
@@ -111,6 +113,11 @@ func (f Caches) AssetsCache() *Cache {
return f[cacheKeyAssets]
}
+// GetResourceCache gets the file cache for remote resources.
+func (f Caches) GetResourceCache() *Cache {
+ return f[cacheGetResource]
+}
+
func DecodeConfig(fs afero.Fs, cfg config.Provider) (Configs, error) {
c := make(Configs)
valid := make(map[string]bool)
diff --git a/cache/filecache/filecache_config_test.go b/cache/filecache/filecache_config_test.go
index acc127e67..1ff3b8112 100644
--- a/cache/filecache/filecache_config_test.go
+++ b/cache/filecache/filecache_config_test.go
@@ -50,7 +50,8 @@ maxAge = "11h"
dir = "/path/to/c2"
[caches.images]
dir = "/path/to/c3"
-
+[caches.getResource]
+dir = "/path/to/c4"
`
cfg, err := config.FromConfigString(configStr, "toml")
@@ -59,7 +60,7 @@ dir = "/path/to/c3"
decoded, err := DecodeConfig(fs, cfg)
c.Assert(err, qt.IsNil)
- c.Assert(len(decoded), qt.Equals, 5)
+ c.Assert(len(decoded), qt.Equals, 6)
c2 := decoded["getcsv"]
c.Assert(c2.MaxAge.String(), qt.Equals, "11h0m0s")
@@ -68,6 +69,10 @@ dir = "/path/to/c3"
c3 := decoded["images"]
c.Assert(c3.MaxAge, qt.Equals, time.Duration(-1))
c.Assert(c3.Dir, qt.Equals, filepath.FromSlash("/path/to/c3/filecache/images"))
+
+ c4 := decoded["getresource"]
+ c.Assert(c4.MaxAge, qt.Equals, time.Duration(-1))
+ c.Assert(c4.Dir, qt.Equals, filepath.FromSlash("/path/to/c4/filecache/getresource"))
}
func TestDecodeConfigIgnoreCache(t *testing.T) {
@@ -94,7 +99,8 @@ maxAge = 3456
dir = "/path/to/c2"
[caches.images]
dir = "/path/to/c3"
-
+[caches.getResource]
+dir = "/path/to/c4"
`
cfg, err := config.FromConfigString(configStr, "toml")
@@ -103,7 +109,7 @@ dir = "/path/to/c3"
decoded, err := DecodeConfig(fs, cfg)
c.Assert(err, qt.IsNil)
- c.Assert(len(decoded), qt.Equals, 5)
+ c.Assert(len(decoded), qt.Equals, 6)
for _, v := range decoded {
c.Assert(v.MaxAge, qt.Equals, time.Duration(0))
@@ -129,7 +135,7 @@ func TestDecodeConfigDefault(t *testing.T) {
c.Assert(err, qt.IsNil)
- c.Assert(len(decoded), qt.Equals, 5)
+ c.Assert(len(decoded), qt.Equals, 6)
imgConfig := decoded[cacheKeyImages]
jsonConfig := decoded[cacheKeyGetJSON]