You need to enable JavaScript to run this app.
Volcano Engine Function as a Service

Volcano Engine Function as a Service

Copy page
Download PDF
Feature application
Using functions to trigger CDN refreshing and preloading from Torch Object Storage (TOS)
Copy page
Download PDF
Using functions to trigger CDN refreshing and preloading from Torch Object Storage (TOS)
This topic describes how to use veFaaS to trigger CDN refreshing and preloading based on TOS.​
Scenario introduction​
Most internet applications adopt a static-dynamic separation architecture, which stores static resources such as videos, audio, pictures, and JS scripts in Torch Object Storage (TOS) and uses CDN to accelerate access. When the resources in TOS are updated or upgraded, the content cached on CDN nodes needs to be synchronized to ensure visitors always get the latest update.​
CDN allows refreshing and preloading cached data manually. However, manual operations are inefficient and error-prone. The veFaaS can help you realize automatic CDN refreshing/preloading when TOS changes, greatly improving maintenance efficiency.​
Background information​
  • CDN: Content Delivery Network (CDN) provides content providers with transmission acceleration services for static content such as images, audio, video, and webpages, delivering a better user experience. For more information, see What is CDN.​
  • Refresh: delete cached content or mark it as expired on the CDN node. When visitors request that content on the node afterward, the node will pull the latest content from the original sites, return it to visitors, and save a copy as well.​
  • Preload: CDN nodes actively pull specific files (usually large files such as videos or installation packages) from the original site and cache them on the nodes. By doing that, the nodes can instantly start file transmission to visitors on receipt of requests. This reduces the delay caused by nodes fetching files from the original sites and avoids excessive download pressure on those sites when too many download requests for large files come in simultaneously.​
Prerequisites​
  • Content delivery network​
  • Volcano Engine CDN has been activated.​
  • The site domains that need acceleration have been added and bound to your TOS bucket (i.e., using the TOS Bucket as the original sites). For details, see Configuring domains for acceleration.​
  • veFaaS​
  • Permission for using veFaaS has been obtained.​
  • Torch Log Service​
  • To use the logging feature, you need to apply for permission in advance to use Volcano Engine Log Service.​
Limits​
  • Preloading and refreshing are only applicable to files, not directories currently.​
  • A function can either perform preloading or refreshing, but not both simultaneously.​
  • CDN has a daily refreshing/preloading quota limit. Tasks cannot be performed if the quota has run out. For details, see Refresh Quota and Preheat Quota.​
Procedure​
Step 1: Create a function using a code template​
Use the vefaas-golang-cdn-refresh-preload code template to create a function, and configure the AK, SK, and other information required by the code as environment variables.​
  1. Log in to the veFaaS console.​
  1. In the top navigation bar, select the target region.​
  1. On the Function page, click Create function.​
  1. The key options on the page and their descriptions are shown below. For other options, see Creating event functions.​
  • ​
    Parameter​
    Description​
    Function type​
    Select Create [Event function].​
    Basic information​
    ​
    Name​
    Enter a function name according to the prompts on the page. Function names cannot be changed after created.​
    Function code​
    ​
    Runtime​
    Select Golang.​
    Deployment method​
    Select Function template > vefaas-golang-cdn-refresh-preload.​
    Advanced settings​
    ​
    Logging​
    Enable logging to save logs.​
    Environment variables​
    You need to set following 4 environment variables:​
    • CloudAPI_AccessKey: enter the ID of API secret access key.​
    • CloudAPI_SecretKey: enter the API secret access key.​
    • TOS_EVENT_TASK_KIND: enter the type of task to execute. Available types:​
    • refresh: (default) file refreshing.​
    • preload: file preloading.​
    • BASE_URL_LIST: enter the URL for which the task is about to execute, e.g., http://cdndomain1/,http://cdndomain2/,http://cdndomain3/. Multiple URLs can be added with commas as separators. When the TOS event triggers the function, each URL in the list will be appended with a TOS file name and then passed on to CDN for refreshing/preloading.​
    ​
  1. Click Create to create the function.​
Step Two: Release the function​
Release the function code and configuration.​
  1. On the function details page, click Release in the upper right corner.​
  1. Select Latest as the function version. Other options can be configured as required.​
  1. Click Confirm to start releasing the function. The function is successfully released if you see the following information on the page.​
Step 3: Configure the TOS trigger​
Configure the rules of TOS trigger for the function.​
  1. Switch to the Trigger tab and click Create trigger.​
  1. Configure the trigger information as required. For details, see Creating TOS triggers.​
  • ​
    Parameter​
    Description​
    Trigger type​
    Select Torch Object Storage.​
    Trigger name​
    Enter a trigger name according to prompts on the page.​
    TOS Bucket​
    Select the TOS Bucket you created according to the prerequisites above.​
    Trigger event​
    Select tos:ObjectCreated:Put and tos:ObjectCreated:CompleteUpload in this example.​
    warning​
    The options tos:ObjectCreated:Put and tos:ObjectCreated:CompleteUpload need to be selected if you about to upload a large file through multipart requests. Otherwise, you can just select tos:ObjectCreated:Put, which triggers the function after a simple object is uploaded.​
    Filter conditions​
    Filter conditions can confine the events that you need to listen for by accurately matching the specified objects, effectively reducing trigger frequency and cost. It is left empty in this example.​
    ​
  1. Click Confirm to create the TOS trigger.​
Validating results​
  • Console validation​
  1. On the trigger tab, select the TOS trigger you just created, click the Bucket name to open the corresponding Bucket page. Click Upload file to upload a file from your local device.​
  1. On the configuration page of the function, click Resource management tab. Click Logging to view the real-time log. You can find messages in the log indicating the refreshing/preloading task has been successfully submitted.​
  1. If logging is enabled for the function, you can go to the Logging tab. On this tab, the same messages can be found as evidence of success.​
  1. Go to the CDN console and click Refresh & Preheat in the left navigation bar, then select Operation Log tab on the page. The information shown in the following screenshot indicates the refreshing/preloading tasks have been performed successfully.​
  • Business validation​
  • Send GET requests to a URL which has been refreshed. The first request will get a response from the TOS of the original site, but the subsequent requests will get from the CDN cache.​
  • Send GET requests to a URL which has been preloaded. The first request will get a response from the CDN cache.​
tip​
You can determine whether the CDN cache is hit by the X-Bdcdn-Cache-Status field in the response header.​
  • X-Bdcdn-Cache-Status: TCP_HIT indicates a hit.​
  • X-Bdcdn-Cache-Status: TCP_MISS indicates a miss.​
Last updated: 2026.08.19 14:06:07