Unverified Commit c8e473a7 authored by Harrison Healey's avatar Harrison Healey Committed by GitHub

Invalidate store cache after making changes (#9211)

* Invalidate store cache after making changes

* Address feedback

* Make cache invalidation in stores always use defer
parent 570c52b4
......@@ -18,7 +18,7 @@ func (s *LocalCacheSupplier) handleClusterInvalidateReaction(msg *model.ClusterM
}
func (s *LocalCacheSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
defer s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
return s.Next().ReactionSave(ctx, reaction, hints...)
}
......
......@@ -53,6 +53,7 @@ func (s *LocalCacheSupplier) SchemeGetAllPage(ctx context.Context, scope string,
func (s *LocalCacheSupplier) SchemePermanentDeleteAll(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
defer s.doClearCacheCluster(s.schemeCache)
defer s.doClearCacheCluster(s.roleCache)
return s.Next().SchemePermanentDeleteAll(ctx, hints...)
}
......@@ -14,9 +14,11 @@ import (
func (s *RedisSupplier) RoleSave(ctx context.Context, role *model.Role, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
key := buildRedisKeyForRoleName(role.Name)
if err := s.client.Del(key).Err(); err != nil {
mlog.Error("Redis failed to remove key " + key + " Error: " + err.Error())
}
defer func() {
if err := s.client.Del(key).Err(); err != nil {
mlog.Error("Redis failed to remove key " + key + " Error: " + err.Error())
}
}()
return s.Next().RoleSave(ctx, role, hints...)
}
......@@ -87,15 +89,17 @@ func (s *RedisSupplier) RoleDelete(ctx context.Context, roleId string, hints ...
result := s.Next().RoleGet(ctx, roleId, hints...)
if result.Err == nil {
role := result.Data.(*model.Role)
key := buildRedisKeyForRoleName(role.Name)
defer func() {
role := result.Data.(*model.Role)
key := buildRedisKeyForRoleName(role.Name)
if err := s.client.Del(key).Err(); err != nil {
mlog.Error("Redis failed to remove key " + key + " Error: " + err.Error())
}
if err := s.client.Del(key).Err(); err != nil {
mlog.Error("Redis failed to remove key " + key + " Error: " + err.Error())
}
}()
}
return result
return s.Next().RoleDelete(ctx, roleId, hints...)
}
func (s *RedisSupplier) RolePermanentDeleteAll(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment