PutObject - caches the uploaded object for single Put operations
(ctx context.Context, bucket, object string, r *PutObjReader, opts ObjectOptions)
| 665 | |
| 666 | // PutObject - caches the uploaded object for single Put operations |
| 667 | func (c *cacheObjects) PutObject(ctx context.Context, bucket, object string, r *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) { |
| 668 | putObjectFn := c.InnerPutObjectFn |
| 669 | dcache, err := c.getCacheToLoc(ctx, bucket, object) |
| 670 | if err != nil { |
| 671 | // disk cache could not be located,execute backend call. |
| 672 | return putObjectFn(ctx, bucket, object, r, opts) |
| 673 | } |
| 674 | size := r.Size() |
| 675 | if c.skipCache() { |
| 676 | return putObjectFn(ctx, bucket, object, r, opts) |
| 677 | } |
| 678 | |
| 679 | // fetch from backend if there is no space on cache drive |
| 680 | if !dcache.diskSpaceAvailable(size) { |
| 681 | return putObjectFn(ctx, bucket, object, r, opts) |
| 682 | } |
| 683 | |
| 684 | if opts.ServerSideEncryption != nil { |
| 685 | dcache.Delete(ctx, bucket, object) |
| 686 | return putObjectFn(ctx, bucket, object, r, opts) |
| 687 | } |
| 688 | |
| 689 | // skip cache for objects with locks |
| 690 | objRetention := objectlock.GetObjectRetentionMeta(opts.UserDefined) |
| 691 | legalHold := objectlock.GetObjectLegalHoldMeta(opts.UserDefined) |
| 692 | if objRetention.Mode.Valid() || legalHold.Status.Valid() { |
| 693 | dcache.Delete(ctx, bucket, object) |
| 694 | return putObjectFn(ctx, bucket, object, r, opts) |
| 695 | } |
| 696 | |
| 697 | // fetch from backend if cache exclude pattern or cache-control |
| 698 | // directive set to exclude |
| 699 | if c.isCacheExclude(bucket, object) { |
| 700 | dcache.Delete(ctx, bucket, object) |
| 701 | return putObjectFn(ctx, bucket, object, r, opts) |
| 702 | } |
| 703 | if c.commitWriteback { |
| 704 | oi, err := dcache.Put(ctx, bucket, object, r, r.Size(), nil, opts, false, true) |
| 705 | if err != nil { |
| 706 | return ObjectInfo{}, err |
| 707 | } |
| 708 | go c.uploadObject(GlobalContext, oi) |
| 709 | return oi, nil |
| 710 | } |
| 711 | if !c.commitWritethrough { |
| 712 | objInfo, err = putObjectFn(ctx, bucket, object, r, opts) |
| 713 | if err == nil { |
| 714 | go func() { |
| 715 | // fill cache in the background |
| 716 | bReader, bErr := c.InnerGetObjectNInfoFn(GlobalContext, bucket, object, nil, http.Header{}, readLock, ObjectOptions{}) |
| 717 | if bErr != nil { |
| 718 | return |
| 719 | } |
| 720 | defer bReader.Close() |
| 721 | oi, _, err := dcache.Stat(GlobalContext, bucket, object) |
| 722 | // avoid cache overwrite if another background routine filled cache |
| 723 | if err != nil || oi.ETag != bReader.ObjInfo.ETag { |
| 724 | dcache.Put(GlobalContext, bucket, object, bReader, bReader.ObjInfo.Size, nil, ObjectOptions{UserDefined: getMetadata(bReader.ObjInfo)}, false, false) |
nothing calls this directly
no test coverage detected