Hash requests a hash of the object and stores in the cache since it might or might not be called, this is lazy loaded
(ctx context.Context, ht hash.Type)
| 317 | // Hash requests a hash of the object and stores in the cache |
| 318 | // since it might or might not be called, this is lazy loaded |
| 319 | func (o *Object) Hash(ctx context.Context, ht hash.Type) (string, error) { |
| 320 | _ = o.refresh(ctx) |
| 321 | o.cacheHashesMu.Lock() |
| 322 | if o.CacheHashes == nil { |
| 323 | o.CacheHashes = make(map[hash.Type]string) |
| 324 | } |
| 325 | cachedHash, found := o.CacheHashes[ht] |
| 326 | o.cacheHashesMu.Unlock() |
| 327 | if found { |
| 328 | return cachedHash, nil |
| 329 | } |
| 330 | if err := o.refreshFromSource(ctx, false); err != nil { |
| 331 | return "", err |
| 332 | } |
| 333 | liveHash, err := o.Object.Hash(ctx, ht) |
| 334 | if err != nil { |
| 335 | return "", err |
| 336 | } |
| 337 | o.cacheHashesMu.Lock() |
| 338 | o.CacheHashes[ht] = liveHash |
| 339 | o.cacheHashesMu.Unlock() |
| 340 | |
| 341 | o.persist() |
| 342 | fs.Debugf(o, "object hash cached: %v", liveHash) |
| 343 | |
| 344 | return liveHash, nil |
| 345 | } |
| 346 | |
| 347 | // persist adds this object to the persistent cache |
| 348 | func (o *Object) persist() *Object { |