11167: Merge branch 'master' into 11167-wb-remove-arvget
[arvados.git] / services / keep-web / cache.go
index 886e5910b5b26ea93a9428e441f273fe316330f6..c29ae7d43c270b129c0bf459aab25df927dc0407 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -114,7 +118,7 @@ func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
 
        var collection *arvados.Collection
        if pdh != "" {
-               collection = c.lookupCollection(pdh)
+               collection = c.lookupCollection(arv.ApiToken + "\000" + pdh)
        }
 
        if collection != nil && permOK {
@@ -146,7 +150,7 @@ func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
                        // PDH changed, but now we know we have
                        // permission -- and maybe we already have the
                        // new PDH in the cache.
-                       if coll := c.lookupCollection(current.PortableDataHash); coll != nil {
+                       if coll := c.lookupCollection(arv.ApiToken + "\000" + current.PortableDataHash); coll != nil {
                                return coll, nil
                        }
                }
@@ -166,7 +170,7 @@ func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
                expire: exp,
                pdh:    collection.PortableDataHash,
        })
-       c.collections.Add(collection.PortableDataHash, &cachedCollection{
+       c.collections.Add(arv.ApiToken+"\000"+collection.PortableDataHash, &cachedCollection{
                expire:     exp,
                collection: collection,
        })
@@ -233,15 +237,13 @@ func (c *cache) collectionBytes() uint64 {
        return size
 }
 
-func (c *cache) lookupCollection(pdh string) *arvados.Collection {
-       if pdh == "" {
-               return nil
-       } else if ent, cached := c.collections.Get(pdh); !cached {
+func (c *cache) lookupCollection(key string) *arvados.Collection {
+       if ent, cached := c.collections.Get(key); !cached {
                return nil
        } else {
                ent := ent.(*cachedCollection)
                if ent.expire.Before(time.Now()) {
-                       c.collections.Remove(pdh)
+                       c.collections.Remove(key)
                        return nil
                } else {
                        atomic.AddUint64(&c.stats.CollectionHits, 1)