diff --git a/pageHandler/pages/index/data.go b/pageHandler/pages/index/data.go index 76fe93b..39222f3 100644 --- a/pageHandler/pages/index/data.go +++ b/pageHandler/pages/index/data.go @@ -14,6 +14,7 @@ type DataYaml struct { MCProtocolVersion int `yaml:"mcProtocolVersion"` MCClientGUID int64 `yaml:"mcClientGUID"` MCTimeout time.Duration `yaml:"mcTimeout"` + MCQueryInterval time.Duration `yaml:"mcQueryInterval"` AllowDisplayState bool `yaml:"allowDisplayState"` AllowDisplayVersion bool `yaml:"allowDisplayVersion"` AllowDisplayActualAddress bool `yaml:"allowDisplayActualAddress"` diff --git a/pageHandler/pages/index/index-page.go b/pageHandler/pages/index/index-page.go index 398b9bd..dc3e8ed 100644 --- a/pageHandler/pages/index/index-page.go +++ b/pageHandler/pages/index/index-page.go @@ -38,6 +38,8 @@ type Page struct { PageTemplateMutex *sync.Mutex PageTemplate *template.Template LastModifiedTemplate time.Time + CachedMC *MC + CollectedMCExpiry time.Time } func (p *Page) GetPath() string { @@ -95,11 +97,25 @@ func (p *Page) GetContents(urlParameters url.Values) (contentType string, conten Parameters: template.URL(p.getNonThemedCleanQuery(urlParameters)), Online: true, } - theMC, err := theMarshal.NewMC() - theMarshal.Queried = theMC - if err != nil { - theMarshal.Online = false + var theMC MC + if time.Now().After(p.CollectedMCExpiry) || time.Now().Equal(p.CollectedMCExpiry) { + theMC, err = theMarshal.NewMC() + if err == nil { + p.CachedMC = &theMC + } else { + theMarshal.Online = false + p.CachedMC = nil + } + p.CollectedMCExpiry = time.Now().Add(theData.MCQueryInterval) + } else { + if p.CachedMC == nil { + theMC = MC{} + theMarshal.Online = false + } else { + theMC = *p.CachedMC + } } + theMarshal.Queried = theMC theBuffer := &io.BufferedWriter{} err = theTemplate.ExecuteTemplate(theBuffer, templateName, theMarshal) if err != nil {