Skip to content

Commit 6040eff

Browse files
committed
[online_image] support HTTP caching
1 parent e9be30a commit 6040eff

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

components/online_image.rst

+22
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ Automations
6666

6767
- **on_download_finished** (*Optional*, :ref:`Automation <automation>`): An automation to perform when the image has been successfully downloaded.
6868

69+
The variable ``cached`` is a boolean available in :ref:`lambdas <config-lambda>` that indicates cache status:
70+
- ``true`` if the image was loaded from cache (cache hit).
71+
- ``false`` if the image was freshly downloaded (cache miss).
72+
73+
Caching follows standard HTTP mechanisms (see `HTTP caching <https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching>`_), utilizing the ``Last-Modified`` and ``ETag`` headers.
74+
75+
For example:
76+
77+
.. code-block:: yaml
78+
79+
online_image:
80+
- url: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"
81+
format: png
82+
id: my_online_image
83+
on_download_finished:
84+
lambda: |-
85+
if (cached) {
86+
ESP_LOGD("online_image", "Cache hit: using cached image");
87+
} else {
88+
ESP_LOGD("online_image", "Cache miss: fresh download");
89+
}
90+
6991
A good example for that is to update the display component after the download succeeded.
7092

7193
- **on_error** (*Optional*, :ref:`Automation <automation>`): An automation to perform when an error happened during download or decode.

0 commit comments

Comments
 (0)