summaryrefslogtreecommitdiffstats
path: root/store/local_cache_supplier_reactions.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-07-31 08:15:23 -0700
committerGitHub <noreply@github.com>2017-07-31 08:15:23 -0700
commit09b49c26ddfdb20ced61e7dfd4192e750ce40449 (patch)
tree1288d069cc8a199b8eb3b858935dffd377ee3d2d /store/local_cache_supplier_reactions.go
parent6f4e38d129ffaf469d40fc8596d3957ee94d21e9 (diff)
downloadchat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.tar.gz
chat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.tar.bz2
chat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.zip
PLT-5308 Caching layer part 2 (#6973)
* Adding Reaction store cache layer example * Implementing reaction store in new caching system. * Redis for reaction store * Adding redis library * Adding invalidation for DeleteAllWithEmojiName and other minor enhancements
Diffstat (limited to 'store/local_cache_supplier_reactions.go')
-rw-r--r--store/local_cache_supplier_reactions.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/store/local_cache_supplier_reactions.go b/store/local_cache_supplier_reactions.go
new file mode 100644
index 000000000..7d2c9f065
--- /dev/null
+++ b/store/local_cache_supplier_reactions.go
@@ -0,0 +1,47 @@
+// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package store
+
+import (
+ "context"
+
+ "github.com/mattermost/platform/model"
+)
+
+func (s *LocalCacheSupplier) handleClusterInvalidateReaction(msg *model.ClusterMessage) {
+ if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
+ s.reactionCache.Purge()
+ } else {
+ s.reactionCache.Remove(msg.Data)
+ }
+}
+
+func (s *LocalCacheSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
+ return s.Next().ReactionSave(ctx, reaction, hints...)
+}
+
+func (s *LocalCacheSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
+ return s.Next().ReactionDelete(ctx, reaction, hints...)
+}
+
+func (s *LocalCacheSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ if result := doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil {
+ return result
+ }
+
+ result := s.Next().ReactionGetForPost(ctx, postId, hints...)
+
+ doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...)
+
+ return result
+}
+
+func (s *LocalCacheSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ // This could be improved. Right now we just clear the whole
+ // cache because we don't have a way find what post Ids have this emoji name.
+ doClearCacheCluster(s.reactionCache)
+ return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...)
+}