Skip to content

Commit

Permalink
Enable static content cache by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Jul 18, 2024
1 parent 8e834bc commit 6bc1efa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The JSON structure for a content file is as follows:

```json
{
"cached": true, // enables the static content cache
"disable_cache": false, // disables the static content cache (does not affect custom handlers)
"path": {
"en": "/", // /404 is a special case serving the 404 not found page
"de": "/de"
Expand Down
1 change: 0 additions & 1 deletion demo/content/home.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"cached": true,
"path": {
"en": "/"
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cms/cms.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cms *CMS) RenderPage(w http.ResponseWriter, r *http.Request, path string,
w.Header().Add(k, v)
}

if page.Cached {
if !page.DisableCache {
data, ok := cms.pageCache[path]

if ok {
Expand Down Expand Up @@ -171,7 +171,7 @@ func (cms *CMS) RenderPage(w http.ResponseWriter, r *http.Request, path string,
slog.Debug("Error sending response", "path", path, "error", err)
}

if page.Cached {
if !page.DisableCache {
cms.m.Lock()
cms.pageCache[path] = data
cms.m.Unlock()
Expand Down
22 changes: 11 additions & 11 deletions pkg/cms/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ type Analytics struct {

// Content is a page or element for the CMS.
type Content struct {
Cached bool `json:"cached"`
Path map[string]string `json:"path"`
Sitemap Sitemap `json:"sitemap"`
Header map[string]string `json:"header"`
Handler string `json:"handler"`
Analytics Analytics `json:"analytics"`
Ref string `json:"ref"`
Tpl string `json:"tpl"`
Data map[string]any `json:"data"`
Copy Copy `json:"copy"`
Content map[string][]Content `json:"content"`
DisableCache bool `json:"disable_cache"`
Path map[string]string `json:"path"`
Sitemap Sitemap `json:"sitemap"`
Header map[string]string `json:"header"`
Handler string `json:"handler"`
Analytics Analytics `json:"analytics"`
Ref string `json:"ref"`
Tpl string `json:"tpl"`
Data map[string]any `json:"data"`
Copy Copy `json:"copy"`
Content map[string][]Content `json:"content"`

// Language is extracted and set from Path automatically.
Language string `json:"-"`
Expand Down

0 comments on commit 6bc1efa

Please sign in to comment.