summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sql_post_store.go')
-rw-r--r--store/sql_post_store.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 900aeeeb6..44ae58b32 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -17,6 +17,17 @@ type SqlPostStore struct {
*SqlStore
}
+const (
+ POSTS_ETAG_CACHE_SIZE = 25000
+ POSTS_ETAG_CACHE_SEC = 900 // 15 minutes
+)
+
+var postEtagCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE)
+
+func ClearPostCaches() {
+ postEtagCache.Purge()
+}
+
func NewSqlPostStore(sqlStore *SqlStore) PostStore {
s := &SqlPostStore{sqlStore}
@@ -210,12 +221,25 @@ type etagPosts struct {
UpdateAt int64
}
-func (s SqlPostStore) GetEtag(channelId string) StoreChannel {
+func (s SqlPostStore) InvalidatePostEtagCache(channelId string) {
+ postEtagCache.Remove(channelId)
+}
+
+func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
+ if allowFromCache {
+ if cacheItem, ok := postEtagCache.Get(channelId); ok {
+ result.Data = cacheItem.(string)
+ storeChannel <- result
+ close(storeChannel)
+ return
+ }
+ }
+
var et etagPosts
err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId})
if err != nil {
@@ -224,6 +248,8 @@ func (s SqlPostStore) GetEtag(channelId string) StoreChannel {
result.Data = fmt.Sprintf("%v.%v.%v", model.CurrentVersion, et.Id, et.UpdateAt)
}
+ postEtagCache.AddWithExpiresInSecs(channelId, result.Data.(string), POSTS_ETAG_CACHE_SEC)
+
storeChannel <- result
close(storeChannel)
}()