Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
    • All guides
    • Connecting to a Cloud CDN provider
      • Creating a resource
      • Editing basic settings of a resource
      • Getting information about a resource
      • Configuring resource caching
      • Configuring log export
      • Pre-loading files to CDN servers
      • Purging resource cache
      • Configuring request and response headers
      • Configuring CORS for responses to clients
      • Configuring HTTP methods
      • Enabling file compression
      • Enabling file segmentation
      • Enabling origin shielding
      • Configuring request redirection
      • Setting up access via a secure token
      • Managing additional resource settings
      • Disabling a resource
      • Managing resource labels
      • Deleting a resource
      • Viewing resource statistics
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • Troubleshooting
  1. Step-by-step guides
  2. Resources
  3. Configuring resource caching

Configuring resource caching

Written by
Yandex Cloud
Updated at May 13, 2025

To configure the caching parameters of a resource:

Management console
CLI
Terraform
API
  1. In the management console, select the folder where your resource is located.

  2. Select Cloud CDN.

  3. Click the resource name.

  4. Go to the Caching tab.

  5. In the top-right corner, click Edit.

  6. Select and configure the caching options:

    • Under CDN:

      • Enable CDN caching.
      • Select the setting type: Same as origin or Custom settings.
      • Select the cache lifetime from the list.
      • (Optional) For the Custom settings setting type, set the cache lifetime for the required HTTP response codes.
    • Under Browser:

      • Enable Browser caching.
  7. Optionally, under Additional settings:

    • Select the option to ignore Cookies.
    • Select the option to ignore the Query parameters.
  8. Click Save.

If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. View the description of the CLI update resource command:

    yc cdn resource update --help
    
  2. Get a list of all resources in the default folder:

    yc cdn resource list --format yaml
    

    Result:

    id: s0me1dkfjq********
    folder_id: s0mef01der7p********
    cname: testexample.com
    created_at: "2022-01-19T09:23:57.921365Z"
    updated_at: "2022-01-19T10:55:30.305141Z"
    active: true
    options:
      edge_cache_settings:
        enabled: true
        default value: "345600"
      cache_http_headers:
        enabled: true
        value:
        - content-type
        - content-length
        - connection
        - server
        - date
        - test
      stale:
        enabled: true
        value:
        - error
        - updating
      allowed_http_methods:
        value:
        - GET
        - POST
        - HEAD
        - OPTIONS
    origin_group_id: "89783"
    origin_group_name: My origins group
    origin_protocol: HTTP
    ssl_certificate:
      type: DONT_USE
      status: READY
    
  3. To change the cache lifetime, run:

    yc cdn resource update <resource_ID> \
      --cache-expiration-time <time> \
      --browser-cache-expiration-time <time> \
      --ignore-cookie true \
      --ignore-query-string
    

    Where:

    • --cache-expiration-time: Cache lifetime in seconds.
    • --browser-cache-expiration-time: Browser cache lifetime in seconds.
    • --ignore-cookie: If true, ignores cookies.
    • --ignore-query-string: Ignores query parameters.

    For more information about the yc cdn resource update command, see the CLI reference.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. In the configuration file, describe the parameters of the yandex_cdn_resource CDN resource you want to create:

    terraform {
      required_providers {
        yandex = {
          source  = "yandex-cloud/yandex"
          version = "0.69.0"
        }
      }
    }
    
    provider "yandex" {
      token     = "<OAuth_token>"
      cloud_id  = "<cloud_ID>"
      folder_id = "<folder_ID>"
      zone      = "<availability_zone>"
    }
    
    resource "yandex_cdn_resource" "my_resource" {
        cname               = "cdn1.yandex-example.ru"
        active              = false
        origin_protocol     = "https"
        secondary_hostnames = ["cdn-example-1.yandex.ru", "cdn-example-2.yandex.ru"]
        origin_group_id     = yandex_cdn_origin_group.my_group.id
        options {
          edge_cache_settings    = "345600"
          browser_cache_settings = "1800"
          ignore_cookie          = true
          ignore_query_params    = false
        }
    
    }
    

    Where:

    • cname: Primary domain name used for content distribution. This is a required parameter.
    • active: Flag indicating content availability to end users. True: CDN content will be available to clients. This is an optional parameter. The default value is true.
    • origin_protocol: Protocol for origins. This is an optional parameter. The default value is http.
    • secondary_hostnames: Additional domain names. This is an optional parameter.
    • origin_group_id: Origin group ID. This is a required parameter. Use the ID from the description of the origin group in the yandex_cdn_origin_group resource.
    • The options section contains additional parameters of CDN resources:
      • browser_cache_settings: Browser cache lifetime in seconds. This is an optional parameter. The default value is 0.
      • edge_cache_settings: Cache lifetime for response codes in seconds. This is an optional parameter. The default value is 345600.
      • ignore_query_params: Ignore query parameters. This is an optional parameter. The default value is false.
      • ignore_cookie: Ignore cookies. This is an optional parameter. The default value is false.

    For more information about the yandex_cdn_resource parameters in Terraform, see the provider documentation.

  2. In the command line, go to the directory with the Terraform configuration file.

  3. Check the configuration using this command:

    terraform validate
    

    If the configuration is correct, you will get this message:

    Success! The configuration is valid.
    
  4. Run this command:

    terraform plan
    

    The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  5. Apply the configuration changes:

    terraform apply
    
  6. Confirm the changes: type yes into the terminal and press Enter.

    You can check the changes to the CDN resource in the management console or using this CLI command:

    yc cdn resource list
    

Use the update REST API method for the Resource resource or the ResourceService/Update gRPC API call.

It may take up to 15 minutes for the new settings of the existing resource to apply to CDN servers. After that, we recommend purging the resource cache.

Was the article helpful?

Previous
Getting information about a resource
Next
Configuring log export
Yandex project
© 2025 Yandex.Cloud LLC