Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalidate cache when modifying or deleting a space #2500

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/invalidate-listproviders-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Invalidate listproviders cache

We now invalidate the related listproviders cache entries when updating or deleting a storage space.

https://github.com/cs3org/reva/pull/2500
9 changes: 7 additions & 2 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorag
Status: status.NewStatusFromErrType(ctx, "gateway could not call UpdateStorageSpace", err),
}, nil
}
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), res.StorageSpace.Root)

id := res.StorageSpace.Root
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), id)
s.cache.RemoveListStorageProviders(id)
return res, nil
}

Expand Down Expand Up @@ -322,7 +325,9 @@ func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorag
}, nil
}

s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), &provider.ResourceId{OpaqueId: req.Id.OpaqueId})
id := &provider.ResourceId{OpaqueId: req.Id.OpaqueId}
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), id)
s.cache.RemoveListStorageProviders(id)

if dsRes.Status.Code != rpc.Code_CODE_OK {
return dsRes, nil
Expand Down
16 changes: 16 additions & 0 deletions internal/grpc/services/gateway/storageprovidercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func (c Caches) RemoveStat(user *userpb.User, res *provider.ResourceId) {
}
}

// RemoveListStorageProviders removes a reference from the listproviders cache
func (c Caches) RemoveListStorageProviders(res *provider.ResourceId) {
if res == nil {
return
}
sid := res.StorageId

cache := c[listproviders]
for _, key := range cache.GetKeys() {
micbar marked this conversation as resolved.
Show resolved Hide resolved
if strings.Contains(key, sid) {
_ = cache.Remove(key)
continue
}
}
}

func initCache(ttlSeconds int) *ttlcache.Cache {
cache := ttlcache.NewCache()
_ = cache.SetTTL(time.Duration(ttlSeconds) * time.Second)
Expand Down