resources: Adjust the remote Get cache so it does not get evicted on restarts
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Nov 2021 15:54:01 +0000 (16:54 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Nov 2021 15:54:01 +0000 (16:54 +0100)
We fill improve this, soon.

resources/resource_factories/create/create.go

index 4832b3cbe5457cd2496d2573c4594ce7eca816aa..4ad3da448d3f5e123bb58fe37f87396ae0f44209 100644 (file)
@@ -156,7 +156,10 @@ func (c *Client) FromRemote(uri string, options map[string]interface{}) (resourc
 
        resourceID := helpers.HashString(uri, options)
 
-       return c.rs.ResourceCache.GetOrCreate(resources.ResourceCacheKey(resourceID), func() (resource.Resource, error) {
+       // This caches to memory and will, in server mode, not be evicted unless the resourceID changes
+       // or the server restarts.
+       // There is ongoing work to improve this.
+       return c.rs.ResourceCache.GetOrCreate(resourceID, func() (resource.Resource, error) {
                method, reqBody, err := getMethodAndBody(options)
                if err != nil {
                        return nil, errors.Wrapf(err, "failed to get method or body for resource %s", uri)