Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Resources
      • Creating a resource
      • Editing basic settings of 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
      • Disabling a resource
      • Deleting a resource
    • Origin groups
      • Creating an origin group
      • Editing an origin group
      • Connecting an origin group to a resource
      • Deleting an origin group
  • Practical guidelines
    • All practical guidelines
    • Publishing game updates
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment of service versions
  • Concepts
    • Service overview
    • Resource
    • Origins and origin groups
    • Exchanging data between clients and the CDN
      • Overview
      • TLS certificates
      • CORS
      • Compressing content
    • Exchanging data between the CDN and origins
      • Overview
      • Host header
      • Content segmentation
      • Origin shielding
    • Caching content
    • Exporting logs
    • Quotas and limits
  • Access management
  • Troubleshooting
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • CacheService
      • OriginGroupService
      • OriginService
      • ProviderService
      • RawLogsService
      • ResourceService
      • OperationService
    • REST
      • Overview
      • Cache
        • Overview
        • prefetch
        • purge
      • OriginGroup
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Origin
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Provider
        • Overview
        • activate
        • listActivated
      • RawLogs
        • Overview
        • activate
        • deactivate
        • get
        • update
      • Resource
        • Overview
        • create
        • delete
        • get
        • getProviderCName
        • list
        • update
  • Pricing policy
  1. Concepts
  2. Caching content

Caching content

Written by
Yandex Cloud
  • Caching on CDN servers
    • Cache lifetime
  • Caching in browsers
  • Cookies and query parameters
  • Preloading content
  • Purging cache

In the CDN resource settings, you can enable content caching to temporarily store the file copies loaded from origins. There are two types of caching: on CDN servers and in the client browsers.

Caching on CDN servers

If caching on CDN servers is enabled for a resource, files are copied from origins to servers when the following events occur:

  • The client requested from the CDN a file that hadn't been cached by the server yet.
  • The lifetime of the file copy on the server expired, and the file changed on the origin since that time (otherwise, the lifetime is extended for the same period).
  • You preloaded files from origins in the resource settings.

Cache lifetime

Until the cache lifetime expires, the CDN server returns a cached copy of the file to the clients without accessing origins.

You can choose one of two modes to define the cache lifetime:

Mode Description
Same as origin The file is cached for the period specified in the origin's response to the request. The origin must add to the response the Cache-Control HTTP header with the directives max-age (specifies the cache lifetime in seconds) and public (allows file caching at any level).
If the origin responded with an HTTP status code 200, 201, 204, 206, 301, 302, 303, 304, 307, or 308, but the response includes no header meeting the above conditions, the file is cached for the period specified in the resource settings. Files from responses with other status codes are not cached if the header is missing.
Custom The default cache lifetime is specified in the resource settings. It applies to all the origin responses with the HTTP status codes 200, 206, 301 and 302. For any status code (regardless of whether it's listed above or not), you can separately specify the cache lifetime that takes precedence over the default time.
If a status code is not included in the list and no cache lifetime is specified for it separately, a file from the response with such a code is not cached.

Caching in browsers

If caching in browsers is enabled for a resource, CDN servers will add the Cache-Control header with the directives max-age (indicates the cache lifetime in seconds) and public (allows file caching at any level) to responses with the HTTP status codes 200, 201, 204, 206, 301, 302, 303, 304, 307, and 308. The cache lifetime is specified in the resource settings.

Files from responses with other status codes are not cached.

Cookies and query parameters

Requests to the CDN server may contain the same path in the URI, but different cookies (the Set-Cookie HTTP header) and/or different query parameters. In the resource settings, you can specify how to cache files corresponding to such requests: save one file copy for all requests (that is, ignore cookies and/or query parameters) or consider them different and cache the file separately for each request.

Preloading content

Individual files can be preloaded from origins, that is, cached manually, without waiting for requests from clients. We recommend that you preload large files (with a size of 200 MB or higher).

You can only preload content that's not on the servers yet. To update the already cached files, purge the cache before preloading.

There are technical limits for preloading.

Purging cache

You can delete cached file copies from CDN servers by purging the cache. This lets you quickly update in the CDN the content that has changed in the origins.

You can purge cache completely or partially. Partial purge is recommended: if you delete copies of all files from the cache, CDN servers will significantly increase the load on the origins, having to access them at every file request.

For partial purging, you can specify the paths to specific files and folders or use the * character representing any string of characters. Each path must start with the / or * character. Examples of paths:

  • /image/foo.png: An individual file.
  • /image/*.jpg: All files in the /image folder with the .JPG extension.
  • *.jpg: All files with the .JPG extension.
  • */static/*: All files that have the /static/ substring in the path.

If the file is cached based on the query parameters (that is, for each request with new parameters, a separate copy was saved), all copies of the file are deleted by default. To delete only specific copies, you need to explicitly specify their query parameters: for example, /image/foo.png?id=12345.

There are technical limits for cache purging.

See also

  • Instructions for configuring caching.
  • Instructions for preloading content.
  • Instructions for purging the cache.

Was the article helpful?

Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
In this article:
  • Caching on CDN servers
  • Cache lifetime
  • Caching in browsers
  • Cookies and query parameters
  • Preloading content
  • Purging cache