History UI: add prefetch and caching (#32699)

This commit is contained in:
Michael Geers 2026-08-10 18:00:10 +02:00 • committed by GitHub
parent 4caddeec5d
commit ea80d136ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 21 deletions

View file

@ -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)
}