diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index f24392fd2..69d7d5ce5 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -87,14 +87,14 @@ type cacheObjects struct { CopyObjectFn func(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (objInfo ObjectInfo, err error) } -func (c *cacheObjects) incHitsToMeta(ctx context.Context, dcache *diskCache, bucket, object string, size int64, eTag string) error { +func (c *cacheObjects) incHitsToMeta(ctx context.Context, dcache *diskCache, bucket, object string, size int64, eTag string, rs *HTTPRangeSpec) error { metadata := make(map[string]string) metadata["etag"] = eTag - return dcache.SaveMetadata(ctx, bucket, object, metadata, size, nil, "", true) + return dcache.SaveMetadata(ctx, bucket, object, metadata, size, rs, "", true) } // Backend metadata could have changed through server side copy - reset cache metadata if that is the case -func (c *cacheObjects) updateMetadataIfChanged(ctx context.Context, dcache *diskCache, bucket, object string, bkObjectInfo, cacheObjInfo ObjectInfo) error { +func (c *cacheObjects) updateMetadataIfChanged(ctx context.Context, dcache *diskCache, bucket, object string, bkObjectInfo, cacheObjInfo ObjectInfo, rs *HTTPRangeSpec) error { bkMeta := make(map[string]string) cacheMeta := make(map[string]string) @@ -119,7 +119,7 @@ func (c *cacheObjects) updateMetadataIfChanged(ctx context.Context, dcache *disk !bkObjectInfo.Expires.Equal(cacheObjInfo.Expires) { return dcache.SaveMetadata(ctx, bucket, object, getMetadata(bkObjectInfo), bkObjectInfo.Size, nil, "", false) } - return c.incHitsToMeta(ctx, dcache, bucket, object, cacheObjInfo.Size, cacheObjInfo.ETag) + return c.incHitsToMeta(ctx, dcache, bucket, object, cacheObjInfo.Size, cacheObjInfo.ETag, rs) } // DeleteObject clears cache entry if backend delete operation succeeds @@ -203,7 +203,7 @@ func (c *cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string } c.cacheStats.incHit() c.cacheStats.incBytesServed(bytesServed) - c.incHitsToMeta(ctx, dcache, bucket, object, cacheReader.ObjInfo.Size, cacheReader.ObjInfo.ETag) + c.incHitsToMeta(ctx, dcache, bucket, object, cacheReader.ObjInfo.Size, cacheReader.ObjInfo.ETag, rs) return cacheReader, nil } if cc != nil && cc.noStore { @@ -256,7 +256,7 @@ func (c *cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string // if ETag matches for stale cache entry, serve from cache if cacheReader.ObjInfo.ETag == objInfo.ETag { // Update metadata in case server-side copy might have changed object metadata - c.updateMetadataIfChanged(ctx, dcache, bucket, object, objInfo, cacheReader.ObjInfo) + c.updateMetadataIfChanged(ctx, dcache, bucket, object, objInfo, cacheReader.ObjInfo, rs) c.incCacheStats(cacheObjSize) return cacheReader, nil } @@ -281,7 +281,7 @@ func (c *cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string // If object has less hits than configured cache after, just increment the hit counter // but do not cache it. if numCacheHits < c.after { - c.incHitsToMeta(ctx, dcache, bucket, object, objInfo.Size, objInfo.ETag) + c.incHitsToMeta(ctx, dcache, bucket, object, objInfo.Size, objInfo.ETag, rs) return bkReader, bkErr }