-func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceReload bool) (map[string]interface{}, error) {
+func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceReload bool) (*arvados.Collection, error) {
c.setupOnce.Do(c.setup)
atomic.AddUint64(&c.stats.Requests, 1)
permOK := false
permKey := arv.ApiToken + "\000" + targetID
c.setupOnce.Do(c.setup)
atomic.AddUint64(&c.stats.Requests, 1)
permOK := false
permKey := arv.ApiToken + "\000" + targetID
ent := ent.(*cachedPermission)
if ent.expire.Before(time.Now()) {
c.permissions.Remove(permKey)
ent := ent.(*cachedPermission)
if ent.expire.Before(time.Now()) {
c.permissions.Remove(permKey)
// 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
// use our cached manifest.
atomic.AddUint64(&c.stats.APICalls, 1)
// 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
// use our cached manifest.
atomic.AddUint64(&c.stats.APICalls, 1)
err := arv.Get("collections", targetID, selectPDH, ¤t)
if err != nil {
return nil, err
}
err := arv.Get("collections", targetID, selectPDH, ¤t)
if err != nil {
return nil, err
}
- if checkPDH, ok := current["portable_data_hash"].(string); !ok {
- return nil, fmt.Errorf("API response for %q had no PDH", targetID)
- } else if checkPDH == pdh {
+ if current.PortableDataHash == pdh {
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
// PDH changed, but now we know we have
// permission -- and maybe we already have the
// new PDH in the cache.
// PDH changed, but now we know we have
// permission -- and maybe we already have the
// new PDH in the cache.
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
})
c.pdhs.Add(targetID, &cachedPDH{
expire: exp,
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
})
c.pdhs.Add(targetID, &cachedPDH{
expire: exp,
-func (c *cache) lookupCollection(pdh string) map[string]interface{} {
- 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 {