Skip to content

Commit

Permalink
invalidate cache when modifying or deleting a space (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Feb 3, 2022
1 parent 1143238 commit 48c06f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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() {
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

0 comments on commit 48c06f9

Please sign in to comment.