diff --git a/api/layer/layer.go b/api/layer/layer.go index e5d1291c..0f81bc4a 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -23,9 +23,10 @@ import ( type ( layer struct { - pool pool.Pool - log *zap.Logger - cache ObjectsListCache + pool pool.Pool + log *zap.Logger + listObjCache ObjectsListCache + } // Params stores basic API parameters. @@ -130,9 +131,9 @@ const ( // and establishes gRPC connection with node. func NewLayer(log *zap.Logger, conns pool.Pool) Client { return &layer{ - pool: conns, - log: log, - cache: newListObjectsCache(defaultCacheLifetime), + pool: conns, + log: log, + listObjCache: newListObjectsCache(defaultObjectsListCacheLifetime), } } diff --git a/api/layer/object.go b/api/layer/object.go index 59700c09..7f90f87f 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -374,7 +374,7 @@ func (n *layer) listAllObjects(ctx context.Context, p ListObjectsParamsCommon) ( return nil, err } - allObjects = n.cache.Get(cacheKey) + allObjects = n.listObjCache.Get(cacheKey) if allObjects == nil { allObjects, err = n.listSortedObjectsFromNeoFS(ctx, allObjectParams{ @@ -387,7 +387,7 @@ func (n *layer) listAllObjects(ctx context.Context, p ListObjectsParamsCommon) ( } // putting to cache a copy of allObjects because allObjects can be modified further - n.cache.Put(cacheKey, append([]*ObjectInfo(nil), allObjects...)) + n.listObjCache.Put(cacheKey, append([]*ObjectInfo(nil), allObjects...)) } return allObjects, nil diff --git a/api/layer/object_cache.go b/api/layer/object_list_cache.go similarity index 89% rename from api/layer/object_cache.go rename to api/layer/object_list_cache.go index ce151576..229d02a1 100644 --- a/api/layer/object_cache.go +++ b/api/layer/object_list_cache.go @@ -13,7 +13,7 @@ import ( request. The cache is a map which has a key: cacheOptions struct and a value: list of objects. After putting a record we - start a timer (via time.AfterFunc) that removes the record after defaultCacheLifetime value. + start a timer (via time.AfterFunc) that removes the record after defaultObjectsListCacheLifetime value. When we get a request from the user we just try to find the suitable and non-expired cache and then we return the list of objects. Otherwise we send the request to NeoFS. @@ -27,15 +27,15 @@ type ( } ) -const defaultCacheLifetime = time.Second * 60 +const defaultObjectsListCacheLifetime = time.Second * 60 type ( listObjectsCache struct { cacheLifetime time.Duration - caches map[cacheOptions]cache + caches map[cacheOptions]cacheEntry mtx sync.RWMutex } - cache struct { + cacheEntry struct { list []*ObjectInfo } cacheOptions struct { @@ -47,7 +47,7 @@ type ( func newListObjectsCache(lifetime time.Duration) *listObjectsCache { return &listObjectsCache{ - caches: make(map[cacheOptions]cache), + caches: make(map[cacheOptions]cacheEntry), cacheLifetime: lifetime, } } @@ -65,7 +65,7 @@ func (l *listObjectsCache) Put(key cacheOptions, objects []*ObjectInfo) { if len(objects) == 0 { return } - var c cache + var c cacheEntry l.mtx.Lock() defer l.mtx.Unlock() c.list = objects diff --git a/api/layer/object_cache_test.go b/api/layer/object_list_cache_test.go similarity index 100% rename from api/layer/object_cache_test.go rename to api/layer/object_list_cache_test.go