X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1b5e5a3ef2c174358693f83849f05ed8276be657..711711827bb0c3564836707bb7d4453c60c6a98c:/services/keep-web/cache.go diff --git a/services/keep-web/cache.go b/services/keep-web/cache.go index ce1168acd2..59e8de3bc9 100644 --- a/services/keep-web/cache.go +++ b/services/keep-web/cache.go @@ -86,6 +86,29 @@ func (c *cache) Stats() cacheStats { } } +// Update saves a modified version (fs) to an existing collection +// (coll) and, if successful, updates the relevant cache entries so +// subsequent calls to Get() reflect the modifications. +func (c *cache) Update(client *arvados.Client, coll arvados.Collection, fs arvados.CollectionFileSystem) error { + c.setupOnce.Do(c.setup) + + if m, err := fs.MarshalManifest("."); err != nil || m == coll.ManifestText { + return err + } else { + coll.ManifestText = m + } + var updated arvados.Collection + defer c.pdhs.Remove(coll.UUID) + err := client.RequestAndDecode(&updated, "PATCH", "arvados/v1/collections/"+coll.UUID, client.UpdateBody(coll), nil) + if err == nil { + c.collections.Add(client.AuthToken+"\000"+coll.PortableDataHash, &cachedCollection{ + expire: time.Now().Add(time.Duration(c.TTL)), + collection: &updated, + }) + } + return err +} + func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceReload bool) (*arvados.Collection, error) { c.setupOnce.Do(c.setup)