How to enforce HLS cache for live streaming delivery

Azion Web Platform allows you to deliver live streaming content in HLS format, being able to easily self-provision and configure your cache policies. This guide covers the step-by-step to enforce HLS cache, manage chunks and playlists caching, set up rules engines rules, and utilize Azion Edge Storage for optimal video delivery.


Requirements


Enforcing cache policies for HLS

To enforce cache policies for HLS in the edge application, follow the steps as explained next.

In this example, an edge application and a domain linked to it has been previously created.

Creating a cache policy for the chunks

First, you must create a cache policy for the chunks:

  1. Open Azion CLI in your terminal.
  2. Get the details of an existing edge application using the list command: azion list edge-application --details
  3. Enable Tiered Cache for your application: $ azion update edge-application --application-id 1234 --l2-caching true
  4. Create an origin: $ azion create origin --application-id 1234 --name "origin-edge" --origin-type single_origin --addresses "example.com" --host-header "example.com"
  5. Configure the cache policy for the chunks: $ azion create cache-setting --application-id 1234 --name "chunks-policy" --browser-cache-settings "override" --browser-cache-settings-maximum-ttl 0 --cdn-cache-settings "override" --cnd-cache-settings-maximum-ttl 60
  • Define Advanced Cache Key behaviors according to your needs. Check the optional flags for the create command.
  • The recommendation is selecting Content does not vary, for Query String and/or Cookies, according to your needs.

Creating cache policies for the playlist

Now configure the cache policy for the playlist: $ azion create cache-setting --application-id 1234 --name "playlist-policy" --browser-cache-settings "override" --browser-cache-settings-maximum-ttl 0 --cdn-cache-settings "override" --cnd-cache-settings-maximum-ttl 5

  • Define Advanced Cache Key behaviors according to your needs. Check the optional flags for the create command.
  • The recommendation is selecting Content does not vary, for Query String and/or Cookies, according to your needs.

Utilizing Azion Edge Storage for HLS video delivery

To deliver MP4 videos using HLS and Azion Edge Storage:

  1. Upload your MP4 video files to Azion Edge Storage.
  2. Configure your encoder to convert MP4 files to HLS format and point to Azion Edge Storage as the origin.
  3. Follow the cache policy setup steps outlined above to ensure efficient video delivery.

Creating Rules Engine rules

Still on the application page, open the Rules Engine tab:

First, create a rule for the chunks:

  1. Click the + Rule button.
  2. Give a name and a description (optional) to your rule.
  3. Select the Request Phase option.
  4. In Criteria, define if ${uri} matches .\*.ts.
  5. In Behaviors, select Set Cache Policy and add the policy for the chunks you created in the previous step.
  6. Click the Save button.

Now, create a rule for the playlist:

  1. Click the + Rule button.
  2. Give a name and a description (optional) to your rule.
  3. Select the Request Phase option.
  4. In Criteria, define if ${uri} matches \*.m3u8.
  5. In Behaviors, select Set Cache Policy and add the policy for the playlist you created in the previous step.
  6. Click the Save button.

Done. Now you can configure your source and encoder pointing to Azion and stream your content, enforcing HLS cache.

Go to Live Streaming Delivery architecture