How to enforce HLS cache for live streaming delivery

Azion Edge 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, managing chunks and playlists caching, and setting up rules engines rules.



Enforcing cache policies for HLS

Section titled 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

Section titled Creating a cache policy for the chunks

First, you must to 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 behavoirs 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

Section titled 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 behavoirs 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.
  1. First, create a rule for the chunks: $ azion create rules-engine --application-id 1234 --phase "request" --file ./chunks-rule.json

In the chunks-rule.json file, include:

{ "name": "chunks-rule", "description": "This is a description for your chunks rule", "criteria": [ [ { "conditional": "if", "variable": "${uri}", "operator": "matches", "input_value": ".\*.ts" } ] ], "behaviors": [ { "name": "set_cache_policy", "target": "chunks-policy" } ]
}
  1. Now, create a rule for the playlist: $ azion create rules-engine --application-id 1234 --phase "request" --file ./playlist-rule.json

In the playlist-rule.json file, include:

{ "name": "playlist-cache-rule", "description": "This is a description for your playlist rule", "criteria": [ [ { "conditional": "if", "variable": "${uri}", "operator": "matches", "input_value": "\*.m3u8" } ] ], "behaviors": [ { "name": "set_cache_policy", "target": "playlist-policy" } ]
}

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

Contributors