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 veFaaS to implement TOS-triggered MCDN refresh and preload
Copy page
Download PDF
Using veFaaS to implement TOS-triggered MCDN refresh and preload
This article introduces how to schedule CDN refresh/preload tasks using veFaaS.​
Scenario introduction​
Refreshing or preloading CDN nodes to ensure consistency between CDN caches and origin content is a common operation for CDN users. Some financial organizations have strict requirements on when changes can be made, for example, allowing changes only in the early morning each day. In such scenarios, manually performing refresh and preload operations is cumbersome and error-prone. Scheduling refresh and preload tasks through veFaaS effectively address this issue.​
Background information​
  • CDN: Content Delivery Network (CDN) provides content providers with transmission acceleration services for static content such as images, audio, video, web pages, and installation packages to optimize the user access experience and improve download speed. For more information, see What is CDN.​
  • Refresh: delete cached content or mark it as expired on the CDN node. The next time a user requests that content from the node, the node pulls the latest content from the origin server, returns it to the user, and caches it.​
  • 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​
  • The CDN is activated.​
  • Your site domain has been added as an acceleration domain. For detailed operations, refer to Add a domain name.​
  • Volcano Engine Function as a Service​
  • veFaaS has been activated.​
  • Torch Log Service (TLS)​
  • To use the function logging feature, activate Volcano Engine TLS in advance.​
Limits​
CDN has quota limits for daily refresh/preload. Exceeding the daily quota may cause task failure on the day of execution. For details, see Refreshing quotas and Preloading quotas.​
Procedure​
Step One: Create the function using a code template​
Create the function using the vefaas-golang-cdn-refresh-preload code template, and configure the AK and SK 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. On the Create function page, select the vefaas-golang-cdn-refresh-preload template and click Next: Function configuration.​
  1. Configure the function information as required.​
  • Basic information​
  • Configure the function name and remarks.​
  • Function code​
  • The code template provides refresh/preload business code and requires no configuration.​
  • Advanced settings​
  • This example only configures the log feature and environment variables; other parameters remain at default settings.​
  • ​
    Parameter​
    Description​
    Logging​
    Enable logging to deliver logs to the default log project.​
    Environment variables​
    Add two new environment variables and configure the AK and SK prepared in the Prerequisites as environment variables. Configuration format:​
    • CloudAPI_AccessKey:xxx​
    • CloudAPI_SecretKey:xxx​
    ​
  1. Click Confirm 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. Function revision uses Latest. Fill in Version description as needed. Keep Maximum number of instances at default settings.​
  1. Click Confirm to start releasing the function. ​
Step Three: Create and enable a scheduled trigger​
Configure a Timer Trigger for the current function and set the rules to trigger the function.​
  1. Switch to the Trigger tab and click Create trigger.​
  1. Configure the trigger information as required.​
  • Trigger type: Select Timer trigger.​
  • Trigger name: Customize the trigger name according to the interface prompt rules.​
  • Push time: Set the trigger cycle and time according to business needs. This example is set to trigger every minute.​
  • Enable immediately: Turn on to allow the trigger to work properly.​
  • Request concurrency: If this option is enabled and the previous request triggered by this trigger has not finished when the next scheduled time arrives, the function does not wait for the previous request to finish and instead processes the next request concurrently.​
  • Trigger message: Pass information such as the task type (refresh/preload) and execution target (URL) to the function through the trigger message.​
tip​
  • Each Timer trigger can only specify one task type.​
  • The trigger message must be in JSON object format. Supported fields are listed in the table below:​
  • ​
    field name​
    Field type​
    Required​
    Description​
    TaskKind​
    string​
    Yes​
    Task type. Optional values include:​
    • refresh: Refresh​
    • preload: Preload​
    TaskType​
    string​
    No​
    This is the refresh task type. Only fill in when TaskKind = refresh. For more information, refer to CDN API reference Type field.​
    Available values:​
    • file (default): File refresh​
    • dir: Directory refresh​
    Urls​
    string​
    Yes​
    Specify one or more content URLs. For more information, refer to CDN API reference Urls field.​
    • Content URLs start with http:// or https://.​
    • Separate multiple content URLs with \n.​
    • The directory specified for refreshing must end with /.​
    • Example: http://example.com/1.txt``\n``http://www.example.com/2.txt​
    ConcurrentLimit​
    int​
    No​
    When TaskKind = preload, specify the number of files the CDN requests from the origin site each time it processes a preload task. For more information, refer to the CDN API reference ConcurrentLimit field.​
    The default value is 10, with a range of 1 to 1,000.​
    ​
  1. Click Confirm to complete the Timer trigger creation.​
Validating results​
  1. Go to the Resource management tab of the current function. Click Logs to view real-time logs of the function instance. You will see the refresh/preload task was successfully submitted.​
  1. If logging is enabled for the function, you can go to the Logging tab. Check the execution logs of the current function to see that the refresh/preload task was successfully submitted.​
  1. Go to the Refresh and preload page in the CDN console and switch to the Operation records tab to check if the refresh/preload task was executed successfully and if the trigger intervals meet expectations.​
Last updated: 2026.08.19 14:06:07