History UI: add prefetch and caching (#32699)
This commit is contained in:
parent
4caddeec5d
commit
ea80d136ca
2 changed files with 44 additions and 21 deletions
|
|
@ -3,11 +3,13 @@ package server
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/core/metrics"
|
||||
"github.com/evcc-io/evcc/server/db"
|
||||
"github.com/evcc-io/evcc/tariff"
|
||||
"github.com/evcc-io/evcc/util/locale"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
|
@ -77,6 +79,10 @@ func energyHistoryHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// data only changes at the next slot boundary
|
||||
maxAge := time.Until(time.Now().Truncate(tariff.SlotDuration).Add(tariff.SlotDuration))
|
||||
w.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", int(maxAge.Seconds())))
|
||||
|
||||
jsonWrite(w, res)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue