Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
cache: Don't store post data once HTML is generated
Browse files Browse the repository at this point in the history
  • Loading branch information
bakape committed Dec 25, 2016
1 parent d076add commit e9995c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cache/getters.go
Expand Up @@ -42,7 +42,7 @@ func getData(s *store, f FrontEnd) (
data interface{}, json []byte, ctr uint64, fresh bool, err error,
) {
// Have cached data
if s.data != nil {
if s.json != nil {
if s.isFresh() {
// No freshness check needed yet
return s.data, s.json, s.updateCounter, false, nil
Expand Down Expand Up @@ -92,7 +92,7 @@ func GetHTML(k Key, f FrontEnd) ([]byte, uint64, error) {
var html []byte
genHTML := func() {
html = []byte(f.RenderHTML(data, json))
s.update(data, json, html)
s.update(nil, json, html)
}
if !fresh {
// If the cache has been filled with a JSON request, it will not have
Expand Down
5 changes: 4 additions & 1 deletion cache/main.go
Expand Up @@ -98,7 +98,10 @@ func (s *store) update(data interface{}, json, html []byte) {
// Calculating the actual memory footprint of the stored post data is
// expensive. Assume it is as big as the JSON. Most probably it's far less
// than that.
newSize := len(json)*2 + len(html)
newSize := len(json) + len(html)
if data != nil {
newSize += len(json)
}

s.data = data
s.json = json
Expand Down

0 comments on commit e9995c0

Please sign in to comment.