Add a caching flag to page provider content.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Captain ALM 2022-07-15 15:37:59 +01:00
parent 9cafe20ff8
commit 3792ff2a4d
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
3 changed files with 7 additions and 6 deletions

View File

@ -65,9 +65,10 @@ func (ph *PageHandler) ServeHTTP(writer http.ResponseWriter, request *http.Reque
if pageContentType == "" {
if provider := ph.PageProviders[actualPagePath]; provider != nil {
pageContentType, pageContent = provider.GetContents(queryCollection)
var canCache bool
pageContentType, pageContent, canCache = provider.GetContents(queryCollection)
lastMod = provider.GetLastModified()
if pageContentType != "" && ph.CacheSettings.EnableContentsCaching {
if pageContentType != "" && canCache && ph.CacheSettings.EnableContentsCaching {
ph.setPageToCache(request.URL, actualQueries, &CachedPage{
Content: pageContent,
ContentType: pageContentType,

View File

@ -9,6 +9,6 @@ type PageProvider interface {
GetPath() string
GetSupportedURLParameters() []string
GetLastModified() time.Time
GetContents(urlParameters url.Values) (contentType string, contents []byte)
GetContents(urlParameters url.Values) (contentType string, contents []byte, canCache bool)
PurgeTemplate()
}

View File

@ -26,13 +26,13 @@ func (tp *TestPage) GetLastModified() time.Time {
return startTime
}
func (tp *TestPage) GetContents(urlParameters url.Values) (contentType string, contents []byte) {
func (tp *TestPage) GetContents(urlParameters url.Values) (contentType string, contents []byte, canCache bool) {
if val, ok := urlParameters["test"]; ok {
if len(val) > 0 {
return "text/plain", ([]byte)("Testing!\r\n" + val[0])
return "text/plain", ([]byte)("Testing!\r\n" + val[0]), len(val) == 1
}
}
return "text/plain", ([]byte)("Testing!")
return "text/plain", ([]byte)("Testing!"), true
}
func (tp *TestPage) PurgeTemplate() {