forked from TrueCloudLab/frostfs-s3-gw
[#231] cache: Add invalidation of ListObjectsCache
In put operations ListObjectsCache remove entries which can contain put object Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
1ece42b23f
commit
be08596c22
3 changed files with 20 additions and 5 deletions
17
api/cache/objectslist.go
vendored
17
api/cache/objectslist.go
vendored
|
@ -2,6 +2,7 @@ package cache
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bluele/gcache"
|
||||
|
@ -25,6 +26,7 @@ type (
|
|||
ObjectsListCache interface {
|
||||
Get(key ObjectsListKey) []*object.ID
|
||||
Put(key ObjectsListKey, oids []*object.ID) error
|
||||
CleanCacheEntriesContainingObject(objectName string, cid *cid.ID)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -83,6 +85,21 @@ func (l *ListObjectsCache) Put(key ObjectsListKey, oids []*object.ID) error {
|
|||
return l.cache.SetWithExpire(key, oids, l.lifetime)
|
||||
}
|
||||
|
||||
// CleanCacheEntriesContainingObject deletes entries containing specified object.
|
||||
func (l *ListObjectsCache) CleanCacheEntriesContainingObject(objectName string, cid *cid.ID) {
|
||||
cidStr := cid.String()
|
||||
keys := l.cache.Keys(true)
|
||||
for _, key := range keys {
|
||||
k, ok := key.(ObjectsListKey)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if cidStr == k.cid && strings.HasPrefix(objectName, k.prefix) {
|
||||
l.cache.Remove(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CreateObjectsListCacheKey returns ObjectsListKey with given CID, method, prefix, and delimiter.
|
||||
func CreateObjectsListCacheKey(cid *cid.ID, prefix string) ObjectsListKey {
|
||||
p := ObjectsListKey{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue