Skip to content

[online_image] support HTTP caching #4906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/online_image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ Automations

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

The variable ``cached`` is a boolean available in :ref:`lambdas <config-lambda>` that indicates cache status:
- ``true`` if the image was loaded from cache (cache hit).
- ``false`` if the image was freshly downloaded (cache miss).

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.

For example:

.. code-block:: yaml

online_image:
- url: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"
format: png
id: my_online_image
on_download_finished:
lambda: |-
if (cached) {
ESP_LOGD("online_image", "Cache hit: using cached image");
} else {
ESP_LOGD("online_image", "Cache miss: fresh download");
}

A good example for that is to update the display component after the download succeeded.

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