resources: Add key to reources.GetRemote options map

If set, `key` will be used as the only cache key element for the resource.

The default behaviour is to calculate the key based on the URL and all the options.

This means that you can now do:

```
{{ $cacheKey := print $url (now.Format "2006-01-02") }}
{{ $resource := resource.GetRemote $url (dict "key" $cacheKey) }}
```

Fixes #9755
This commit is contained in:
Bjørn Erik Pedersen
2022-04-11 10:34:08 +02:00
parent f8c4e1690a
commit 2dbdf38a54
5 changed files with 70 additions and 1 deletions

View File

@@ -171,3 +171,26 @@ func TestRenameKeys(t *testing.T) {
t.Errorf("Expected\n%#v, got\n%#v\n", expected, m)
}
}
func TestLookupEqualFold(t *testing.T) {
c := qt.New(t)
m1 := map[string]any{
"a": "av",
"B": "bv",
}
v, found := LookupEqualFold(m1, "b")
c.Assert(found, qt.IsTrue)
c.Assert(v, qt.Equals, "bv")
m2 := map[string]string{
"a": "av",
"B": "bv",
}
v, found = LookupEqualFold(m2, "b")
c.Assert(found, qt.IsTrue)
c.Assert(v, qt.Equals, "bv")
}