Skip to main content

Caching Settings

Caching means temporarily storing web documents and data to reduce latency and increase efficiency. In the Arvancloud CDN, when caching is enabled for a domain, website data is stored (cached) at different points and layers for faster access, better efficiency, and higher availability.

How Page Caching Works​

In this method, a copy of the website's resources is stored on edge servers. When a user enters a website's address in their browser and that website uses a CDN, the browser's request is sent to the nearest CDN server. On receiving the request, this server looks for the requested resources in its cache. If it finds the requested resource in its cache and the resource is still valid (in other words, has not expired), it sends it to the browser immediately. But if it doesn't have the resource in its cache or finds it expired, it sends a request for the resource to the origin server hosting the site, and after receiving the resources from the origin server, stores them for itself and also sends them to the user's browser.

Note that not all web data can be cached, and some requests must always be sent to the origin server. Static data such as images, JS and CSS files, and the like are usually cached. Data served from the cache is called a Hit, and if it is not in the cache and has to be fetched from the origin server, it is called a Miss.

To check whether content is a Miss or a Hit, simply check the response header named X-Cache. To view response headers in Chrome, open the settings menu, click More Tools, and then Developer Tools.

CDN Page Caching vs. Browser Caching​

Unlike browser caching, where you only have limited control over how resources are stored in the user's browser and what type of resources are stored for how long, with proxy caching the website administrator can specify these resources and how they are stored on CDN servers precisely, so there is much more oversight and control over these policies.

In addition, with proxy caching there is no difference between a user visiting the website for the first time (or a user who has cleared their browser cache) and a user visiting the website for the umpteenth time. In both cases, the edge server delivers the resource to the user as fast as possible.

To review the caching settings of the Arvancloud CDN, go to Caching Settings in the CDN menu. On the page that opens, you can review and change the cache level, the max age of cached data, purge cached data, and manage Always Online and Development Mode.

This guide covers the caching features of Arvancloud.

Cache Level​

Arvancloud lets you enable different caching levels for your website.

  • Off: In this mode, no data is cached and all requests are sent to the origin server.

  • Without Query String: In this mode, the query string in the URL is ignored, and all requests sent to the same URL but with different query strings receive the same content from the cache.

    For example, if the request:

    https://www.arvancloud.ir/assets/images/pages/cdn/cloudDNS.svg?x=test

    was previously sent to the CDN and stored in the cache, the request:

    https://www.arvancloud.ir/assets/images/pages/cdn/cloudDNS.svg?x=abcdefg1234

    is also served from the cache (it will be a Hit).

  • With Query String: In this mode, unlike the previous one, all query strings are taken into account, and two requests to the same URL but with different query strings are stored as two different pieces of content in the cache. So, for the same two requests from the previous mode, both would be a Miss.

To manage the cache level via API, you can use the following sample requests:

Turning off the cache:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY' \
--header 'content-type: application/json' \
--data '{"cache_status":"off"}'

Enabling the Without Query String level:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--data '{"cache_status":"uri"}'

Enabling the With Query String level:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--data '{"cache_status":"query_string"}'

In the Arvancloud CDN, the maximum cacheable size for each file is 104,857,600 bytes (100 MB) by default and can be increased to 128 MB. This value is 256 MB on the Growth plan, 512 MB on the Professional plan, and up to 2048 MB on the Enterprise plan.

Purge Cache​

Sometimes you need to delete the data in the cache. You can do this in two ways in the Arvancloud panel, which are described below.

  • Specific URL Purge: If you want specific files to be removed from the cache, click this option, enter their URLs, and purge them selectively.

    To use this feature via API, you can use the following request:

    curl --location 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching/purge' \
    --header 'authority: napi.arvancloud.ir' \
    --header 'accept: application/json, text/plain, */*' \
    --header 'authorization: API KEY 1 2 3 4' \
    --header 'content-type: application/json' \
    --data '{"purge":"individual","purge_urls":["http://example.com/purge"]}'

    In this request, the cache of the path http://example.com/purge is purged.

  • Purge All: Click this option to purge all data in the cache for each of your domains.

    To purge a domain's entire cache via API, use the following sample request:

    curl --location 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching/purge' \
    --header 'authority: napi.arvancloud.ir' \
    --header 'accept: application/json, text/plain, */*' \
    --header 'authorization: API KEY 1 2 3 4' \
    --header 'content-type: application/json' \
    --data '{"purge":"all"}'

Cache Max Age​

In this section, you can set the desired durations for different caching levels, which are explained below.

  • Cache Max Age: The length of time stored data stays in the cache. After this time, the data is removed from the cache and fetched from the origin server.

    To change this value via API, you can use the following sample request:

    curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
    --header 'authority: napi.arvancloud.ir' \
    --header 'accept: application/json, text/plain, */*' \
    --header 'authorization: API KEY 1 2 3 4' \
    --header 'content-type: application/json' \
    --data '{"cache_page_200":"1m"}'
  • Cache Max Age for Error Pages: The length of time pages with status codes other than 200 are cached on CDN edge servers.

    To change this value via API, you can use the following sample request:

    curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
    --header 'authority: napi.arvancloud.ir' \
    --header 'accept: application/json, text/plain, */*' \
    --header 'authorization: API KEY 1 2 3 4' \
    --header 'cache-control: no-cache' \
    --header 'content-type: application/json' \
    --data '{"cache_page_any":"3m"}'
  • Browser Cache TTL: The length of time the browser is allowed to store (cache) data.

    To change this value via API, you can use the following sample request:

    curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
    --header 'authority: napi.arvancloud.ir' \
    --header 'accept: application/json, text/plain, */*' \
    --header 'authorization: API KEY 1 2 3 4' \
    --header 'content-type: application/json' \
    --data '{"cache_browser":"1m"}'

If this option is off, responses from the server that have a Set-Cookie header are not cached; if it is on, these pages are cached.

This feature can be configured on the Growth, Professional, and Enterprise plans.

To change this value via API, you can use the following sample request:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--data '{"cache_ignore_sc":true}'

In this request, the cache_ignore_sc key accepts true and false.

Development Mode​

Sometimes you need to completely disable caching temporarily to check changes on your website while developing.

By turning on this option, you can temporarily disable caching. Data that has already been cached remains and is not deleted. After you turn off this option, requests are served from the cache again.

To change this feature via API, you can use the following sample request:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--header 'origin: https://panel.arvancloud.ir' \
--data '{"cache_developer_mode":true}'

In this request, the cache_developer_mode key accepts true and false.

Always Online​

When this option is on, the Arvancloud CDN can respond to user requests with the data in the cache when your website goes down.

Note that when the website is down, new data cannot be cached on the CDN, so before any problem occurs on your website, you can set appropriate page rules to specify what should be cached.

To change this feature via API, you can use the following sample request:

curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/caching' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--data '{"cache_consistent_uptime":false}'

In this request, the cache_consistent_uptime key accepts true and false.

Using Always Online for a Static Version of the Website​

One of the key factors for search engines in SEO is uptime and the site's availability to users. Keeping the website up and making sure its static version is available when the origin server goes down is very important for keeping the site's ranking in search engine results.

With Always Online, you can add a page rule to cache HTML files, cache your domain's root address, and provide a static version of the website to search engines.

Note that, by default, the .html format is not cacheable.

To do this, create a new page rule from CDN > Page Rules. For example, create a page rule for the path *example.com* and enable caching.

Note that you must give this rule a higher priority than the other caching rules you have set.

Default Cacheable Extensions in the Arvancloud CDN​

When you activate the Arvancloud CDN for your site, if you don't define any rule for your website in Page Rules in the CDN menu of the Arvancloud panel, a group of files is automatically stored on Arvancloud edge servers based on the default rule, and no extra settings are needed for them to be cached. These extensions are:

7ZCSVGIFMIDIPNGTIFZIP
AVIDOCGZMKVPPTTIFFZST
AVIFDOCXICOMP3PPTXTTF
APKDMGISOMP4PSWEBM
BINEJSJAROGGRARWEBP
BMPEOTJPGOTFSVGWOFF
BZ2EPSJPEGPDFSVGZWOFF2
CLASSEXEJSPICTSWFXLS
CSSFLACMIDPLSTARXLSX