forked from TrueCloudLab/frostfs-s3-gw
[#547] Cache ObjectInfo instead of Object
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
127b91a97f
commit
42a761c1f2
3 changed files with 37 additions and 76 deletions
38
api/cache/objects.go
vendored
38
api/cache/objects.go
vendored
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/bluele/gcache"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -39,23 +38,6 @@ func New(config *Config) *ObjectsCache {
|
|||
return &ObjectsCache{cache: gc, logger: config.Logger}
|
||||
}
|
||||
|
||||
// Get returns a cached object.
|
||||
func (o *ObjectsCache) Get(address oid.Address) *object.Object {
|
||||
entry, err := o.cache.Get(address.EncodeToString())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
result, ok := entry.(object.Object)
|
||||
if !ok {
|
||||
o.logger.Warn("invalid cache entry type", zap.String("actual", fmt.Sprintf("%T", entry)),
|
||||
zap.String("expected", fmt.Sprintf("%T", result)))
|
||||
return nil
|
||||
}
|
||||
|
||||
return &result
|
||||
}
|
||||
|
||||
// GetObject returns a cached object info.
|
||||
func (o *ObjectsCache) GetObject(address oid.Address) *data.ObjectInfo {
|
||||
entry, err := o.cache.Get(address.EncodeToString())
|
||||
|
@ -65,30 +47,14 @@ func (o *ObjectsCache) GetObject(address oid.Address) *data.ObjectInfo {
|
|||
|
||||
result, ok := entry.(*data.ObjectInfo)
|
||||
if !ok {
|
||||
o.logger.Warn("invalid cache entry type", zap.String("actual", fmt.Sprintf("%T", entry)),
|
||||
zap.String("expected", fmt.Sprintf("%T", result)))
|
||||
return nil
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Put puts an object to cache.
|
||||
func (o *ObjectsCache) Put(obj object.Object) error {
|
||||
cnrID, ok := obj.ContainerID()
|
||||
if !ok {
|
||||
return fmt.Errorf("empty container id")
|
||||
}
|
||||
objID, ok := obj.ID()
|
||||
if !ok {
|
||||
return fmt.Errorf("empty object id")
|
||||
}
|
||||
|
||||
var addr oid.Address
|
||||
addr.SetContainer(cnrID)
|
||||
addr.SetObject(objID)
|
||||
|
||||
return o.cache.Set(addr.EncodeToString(), obj)
|
||||
}
|
||||
|
||||
// PutObject puts an object info to cache.
|
||||
func (o *ObjectsCache) PutObject(obj *data.ObjectInfo) error {
|
||||
cnrID := obj.CID.EncodeToString()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue