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 trigger CDN refresh/preload at a scheduled time
Copy page
Download PDF
Using veFaaS to trigger CDN refresh/preload at a scheduled time
This article introduces how to trigger CDN refresh/preload tasks at a scheduled time using veFaaS.​
Scenario introduction​
Refreshing or preloading CDN nodes to ensure the consistency between CDN cache and origin server content is a common operation for CDN users. Some financial enterprises have strict requirements for change timing, such as allowing changes only during early morning hours daily. 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 log feature of the function, activate the Volcano Engine TLS in advance.​
Limits ​
CDN has daily quotas for refresh/preload. If refresh/preload exceeds the daily quota on the day of execution, it might cause the task failure. For details, refer to Refresh quota and Preload quota.​
Procedure​
Step One: Create a function using the code template​
Use the code template vefaas-golang-cdn-refresh-preload to create a function, and configure the AK and SK required 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 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 the log feature, and specify the default log set.​
    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 Create to create the function.​
Step Two: Release the function​
Release the current code and configuration of the function online.​
  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. Successful function release is shown in the figure below.​
Step Three: Create and enable a scheduled Trigger​
Configure a Timer Trigger for the current function and set the rules for triggering 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: After turning on, when the specific trigger has not finished the last request, it will not wait until the last request is finished and directly processes the next request in concurrency. This example does not enable it.​
  • 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​
    Refresh task type, only required when TaskKind = refresh. For more information, refer to CDN API reference Type field. Optional values include:​
    • 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\nhttp://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 CDN API reference ConcurrentLimit field. The default value is 10, with a value range of 1-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