Add a caching flag to page provider content.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9cafe20ff8
commit
3792ff2a4d
@ -65,9 +65,10 @@ func (ph *PageHandler) ServeHTTP(writer http.ResponseWriter, request *http.Reque
|
|||||||
|
|
||||||
if pageContentType == "" {
|
if pageContentType == "" {
|
||||||
if provider := ph.PageProviders[actualPagePath]; provider != nil {
|
if provider := ph.PageProviders[actualPagePath]; provider != nil {
|
||||||
pageContentType, pageContent = provider.GetContents(queryCollection)
|
var canCache bool
|
||||||
|
pageContentType, pageContent, canCache = provider.GetContents(queryCollection)
|
||||||
lastMod = provider.GetLastModified()
|
lastMod = provider.GetLastModified()
|
||||||
if pageContentType != "" && ph.CacheSettings.EnableContentsCaching {
|
if pageContentType != "" && canCache && ph.CacheSettings.EnableContentsCaching {
|
||||||
ph.setPageToCache(request.URL, actualQueries, &CachedPage{
|
ph.setPageToCache(request.URL, actualQueries, &CachedPage{
|
||||||
Content: pageContent,
|
Content: pageContent,
|
||||||
ContentType: pageContentType,
|
ContentType: pageContentType,
|
||||||
|
@ -9,6 +9,6 @@ type PageProvider interface {
|
|||||||
GetPath() string
|
GetPath() string
|
||||||
GetSupportedURLParameters() []string
|
GetSupportedURLParameters() []string
|
||||||
GetLastModified() time.Time
|
GetLastModified() time.Time
|
||||||
GetContents(urlParameters url.Values) (contentType string, contents []byte)
|
GetContents(urlParameters url.Values) (contentType string, contents []byte, canCache bool)
|
||||||
PurgeTemplate()
|
PurgeTemplate()
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ func (tp *TestPage) GetLastModified() time.Time {
|
|||||||
return startTime
|
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 val, ok := urlParameters["test"]; ok {
|
||||||
if len(val) > 0 {
|
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() {
|
func (tp *TestPage) PurgeTemplate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user