Skip to content

Commit

Permalink
Extend expire time of cached link preview data to a week
Browse files Browse the repository at this point in the history
There's no need to invalidate cache and send request again frequently
  • Loading branch information
jostyee committed Mar 4, 2017
1 parent cf454fb commit 555ac63
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/post.go
Expand Up @@ -14,7 +14,10 @@ import (
"github.com/mattermost/platform/utils"
)

const OPEN_GRAPH_METADATA_CACHE_SIZE = 10000
const (
OPEN_GRAPH_METADATA_CACHE_SIZE = 10000
openGraphDataCacheExpireTime = 604800
)

var openGraphDataCache = utils.NewLru(OPEN_GRAPH_METADATA_CACHE_SIZE)

Expand Down Expand Up @@ -470,7 +473,7 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
og := app.GetOpenGraphMetadata(url)

ogJSON, err := og.ToJSON()
openGraphDataCache.AddWithExpiresInSecs(props["url"], ogJSON, 3600) // Cache would expire after 1 hour
openGraphDataCache.AddWithExpiresInSecs(props["url"], ogJSON, openGraphDataCacheExpireTime) // Cache would expire after 1 week
if err != nil {
w.Write([]byte(`{"url": ""}`))
return
Expand Down

0 comments on commit 555ac63

Please sign in to comment.