permOK := false
permKey := arv.ApiToken + "\000" + targetID
- if ent, cached := c.permissions.Get(permKey); cached {
+ if forceReload {
+ } else if ent, cached := c.permissions.Get(permKey); cached {
ent := ent.(*cachedPermission)
if ent.expire.Before(time.Now()) {
c.permissions.Remove(permKey)
var pdh string
if arvadosclient.PDHMatch(targetID) {
pdh = targetID
+ } else if forceReload {
} else if ent, cached := c.pdhs.Get(targetID); cached {
ent := ent.(*cachedPDH)
if ent.expire.Before(time.Now()) {
}
}
- collection := c.lookupCollection(pdh)
-
- if collection != nil && permOK && !forceReload {
- return collection, nil
+ var collection map[string]interface{}
+ if pdh != "" {
+ collection = c.lookupCollection(pdh)
}
- if collection != nil {
+ if collection != nil && permOK {
+ return collection, nil
+ } else if collection != nil {
// Ask API for current PDH for this targetID. Most
// likely, the cached PDH is still correct; if so,
// _and_ the current token has permission, we can
c.Check(cache.Stats().PDHHits, check.Equals, uint64(4+0+18))
c.Check(cache.Stats().APICalls, check.Equals, uint64(1+1+2))
}
+
+func (s *UnitSuite) TestCacheForceReloadByPDH(c *check.C) {
+ arv, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, check.Equals, nil)
+
+ cache := DefaultConfig().Cache
+
+ for _, forceReload := range []bool{false, true, false, true} {
+ _, err := cache.Get(arv, arvadostest.FooPdh, forceReload)
+ c.Check(err, check.Equals, nil)
+ }
+
+ c.Check(cache.Stats().Requests, check.Equals, uint64(4))
+ c.Check(cache.Stats().CollectionHits, check.Equals, uint64(3))
+ c.Check(cache.Stats().PermissionHits, check.Equals, uint64(1))
+ c.Check(cache.Stats().PDHHits, check.Equals, uint64(0))
+ c.Check(cache.Stats().APICalls, check.Equals, uint64(3))
+}
+
+func (s *UnitSuite) TestCacheForceReloadByUUID(c *check.C) {
+ arv, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, check.Equals, nil)
+
+ cache := DefaultConfig().Cache
+
+ for _, forceReload := range []bool{false, true, false, true} {
+ _, err := cache.Get(arv, arvadostest.FooCollection, forceReload)
+ c.Check(err, check.Equals, nil)
+ }
+
+ c.Check(cache.Stats().Requests, check.Equals, uint64(4))
+ c.Check(cache.Stats().CollectionHits, check.Equals, uint64(1))
+ c.Check(cache.Stats().PermissionHits, check.Equals, uint64(1))
+ c.Check(cache.Stats().PDHHits, check.Equals, uint64(1))
+ c.Check(cache.Stats().APICalls, check.Equals, uint64(3))
+}