http plugin: `cache` is silently ineffective when the upstream sends `Cache-Control: no-store` / `max-age=0`
Describe the bug
A custom http plugin source ignores its configured cache: duration when the upstream responds with Cache-Control: no-store (or max-age=0). evcc then refetches on every control interval. For an API with a request budget this silently exceeds the limit, and the user gets no hint that cache: had no effect.
Root cause: when cache > 0, the plugin tries to force caching by removing cache busting headers, but dropNoCache strips only the no-cache token, not no-store or max-age=0:
https://github.com/evcc-io/evcc/blob/7753d888091d62b2de0b2ccbd88e071a512f82a8/plugin/http.go#L111-L116
https://github.com/evcc-io/evcc/blob/7753d888091d62b2de0b2ccbd88e071a512f82a8/plugin/http.go#L151-L160
So any remaining no-store / max-age=0 still defeats the cache layer.
Related: #27244 describes the same class of problem from the other side (re polling every interval on error). This report is about the cache being bypassed even on success.
Steps to reproduce
-
Start a local endpoint that returns JSON with a value that changes on every request and sends the same cache headers a real flaky cloud API sends. Minimal stub (
python3 stub.py):import http.server COUNT = 0 class H(http.server.BaseHTTPRequestHandler): def do_GET(self): global COUNT; COUNT += 1 body = ('{"power": %d}' % COUNT).encode() self.send_response(200) self.send_header("Content-Type", "application/json") self.send_header("Cache-Control", "no-store, no-cache, max-age=0, must-revalidate") self.send_header("Pragma", "no-cache") self.send_header("Content-Length", str(len(body))) self.end_headers(); self.wfile.write(body) http.server.HTTPServer(("0.0.0.0", 8888), H).serve_forever() -
Run evcc with the config below (
cache: 5m,interval: 10s). -
Watch the trace log.
Expected: the source is fetched at most once per 5 minutes (the configured cache). Actual: it is fetched every 10 seconds (every interval); the read value increments 1, 2, 3, ... every cycle, proving no caching.
Configuration details
network:
port: 7070
log: trace
interval: 10s
meters:
- name: teststub
type: custom
power:
source: http
uri: http://127.0.0.1:8888/p
jq: .power
cache: 5m
site:
meters:
grid: teststub
Log details
evcc trace log (note the GET every 10s and the changing value despite `cache: 5m`):
[teststub] TRACE GET http://127.0.0.1:8888/p
[teststub] TRACE {"power": 1}
[teststub] TRACE GET http://127.0.0.1:8888/p
[teststub] TRACE {"power": 2}
[teststub] TRACE GET http://127.0.0.1:8888/p
[teststub] TRACE {"power": 3}
[teststub] TRACE GET http://127.0.0.1:8888/p
[teststub] TRACE {"power": 4}
[teststub] TRACE GET http://127.0.0.1:8888/p
[teststub] TRACE {"power": 5}
5 fetches in 45 s with `cache: 5m` (expected: 1). Same against the real SolarEdge
monitoring API, whose response carries
`cache-control: no-store, no-cache, max-age=0, must-revalidate`, `expires: 0`.
What type of operating system or environment does evcc run on?
Docker container
External automation
- [x] I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.
Nightly build
- [x] I have verified that the issue is reproducible with the latest nightly build
Version
0.309.1