|
| 1 | +.. _install_sandboxes_cache_mirror: |
| 2 | + |
| 3 | +Caching mirror |
| 4 | +============== |
| 5 | + |
| 6 | +.. sidebar:: Requirements |
| 7 | + |
| 8 | + .. include:: _include/docker-env-setup-link.rst |
| 9 | + |
| 10 | + :ref:`curl <start_sandboxes_setup_curl>` |
| 11 | + Used to make ``HTTP`` requests. |
| 12 | + |
| 13 | +This is a simple example to demonstrate caching resources from an upstream, validating their contents against known checksums using the ``ChecksumFilter``. |
| 14 | + |
| 15 | +This can be useful, for example, to cache build assets for improved speed or reliability. |
| 16 | + |
| 17 | +The example uses a backend that serves 2 endpoints ``/foo`` and ``/bar``, that are expected to return ``FOO`` and ``BAR`` respectively. |
| 18 | + |
| 19 | +In the latter case it does not and therefore fails validation and is not cached or proxied. |
| 20 | + |
| 21 | +The cache mirror inserts a cache-forever header in any validated resources to ensure they are cached without expiry. (TODO) |
| 22 | + |
| 23 | +Step 1: Start all of our containers |
| 24 | +*********************************** |
| 25 | + |
| 26 | +Change to the ``examples/cache-mirror`` directory. |
| 27 | + |
| 28 | +.. code-block:: console |
| 29 | +
|
| 30 | + $ pwd |
| 31 | + envoy/examples/cache-mirror |
| 32 | + $ docker compose pull |
| 33 | + $ docker compose up --build -d |
| 34 | + $ docker compose ps |
| 35 | +
|
| 36 | + NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS |
| 37 | + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 38 | + cache-mirror-backend-1 cache-mirror-backend "/docker-entrypoint.…" backend 6 seconds ago Up 5 seconds 10000/tcp |
| 39 | + cache-mirror-mirror-proxy-1 cache-mirror-mirror-proxy "/docker-entrypoint.…" mirror-proxy 6 seconds ago Up 5 seconds 0.0.0.0:10000->10000/tcp, :::10000->10000/tcp |
| 40 | +
|
| 41 | +
|
| 42 | +Step 2: Fetch the cached asset |
| 43 | +****************************** |
| 44 | + |
| 45 | +Step 3: Check the stats |
| 46 | +*********************** |
| 47 | + |
| 48 | +Step 4: Fetch the cached asset again |
| 49 | +************************************ |
| 50 | + |
| 51 | +Step 5: Confirm the asset was served from cache |
| 52 | +*********************************************** |
| 53 | + |
| 54 | +Step 6: Fetch cached asset with invalid checksum |
| 55 | +************************************************ |
| 56 | + |
| 57 | +Step 7: Confirm the asset was not cached |
| 58 | +**************************************** |
| 59 | + |
| 60 | + |
| 61 | +.. seealso:: |
| 62 | + |
| 63 | + :ref:`Envoy Cache filter configuration <config_http_filters_cache>` |
| 64 | + Learn more about configuring the Envoy Cache filter. |
0 commit comments