How to setup the CDN caching period for my images?

CDN caching accelerates the loading times of images as it allows to cache them as close as possible to your end-users. By using CDN caching, your ensure maximum performance of your website; this is also true for local website with an 80%+ audience geo-localised in one single country.

You can setup caching expiration period per Cloudimage token or per individual image URL. When both are set up, the individual expiration period has greater priority than the token's.

Individual Caching Interval

It is set up using the Cloudimage parameter ci_cache=X, where X is measured in seconds.

Example:

I would like to set up the Caching Interval for my image to be equal to 1 week.
1 week = 604800 sec, so I write:
www.token.cloudimage.io/v7/some_image_url?ci_cache=604800

Default Caching Interval per token:

When a new Cloudimage token is created, it comes by default with the following settings:

Screenshot_2021-09-07_at_16.29.22.png

max-age (Browser cache expiration interval) - it defines how long the image will remain in the browser's cache on the website visitor's local machine. By default this period is 30 days.

s-maxage (CDN cache expiration interval) - it defines how long the image will remain in the cache of the CDN servers. By default this period is 1 year.

Automatic origin image refresh - if activated, Cloudimage won't keep a copy of the image version in its cache. When the s-maxage expires, the CDN server request new image version from Cloudimage. If it exists in the Cloudimage cache, then it is served back to the CDN server. If it doesn't exist, Cloudimage requests the original image from the Origin server.  By default this functionality is deactivated but if you need your image to be fetched from the Origin server every time when s-maxage expires (see the examples below), then activate it.

Tips how and when to modify the Default Caching Interval settings:

  • The images kept in the CDN cache are part of your Image Cache (the Storage). For best service performance and optimal size of the Storage, the CDN caching interval should be in accordance with the average "life span" of the images in your website.
    Example:
    I have a website for selling of Real Estate properties. From the moment of publishing of the offer till the moment of its removal from the website, usually pass 2-4 months. There is no need to set up the CDN caching interval (s-maxage) to keep the images in my Storage for period of 1 year. A shorter period (like 6 months) would be more appropriate in this case.

  • The Automatic origin image refresh is useful in situations when the "life span" of the original images is very short and you do not want the Cloudimage cache to keep some old version of the file, while the version in the Origin server is already updated. Usually this setting is used in combination with a short s-maxage value.
    Example:
    My website serves rotating images but static image URLs without versioning. I set up the s-maxage value to be 3600 (1 hour). Since the Cloudimage servers also keep some cache of the image versions and I do not want this cache to be used, I activate the Automatic origin image refresh. In this way, every time when the s-maxage value expires, Cloudimage will request new fresh copy of the image directly from the Origin server.
    Important note: Please do not set too low s-maxage value and do not activate the Automatic origin image refresh, if you don't have some serious reason to do that. Every time when the s-maxage expires and the CDN cache is flushed, the image is requested from the Cloudimage servers and/or the Origin server. If Cloudimage doesn't keep the image version as cache, it needs to re-process and optimise it again, before to deliver it back to the CDN server. This action takes time and if the s-maxage is incorrectly set up to flush the CDN cache too often when this is not necessary, that may lead to slowing of the image performance in your website. 

  • The process of manual flushing of the CDN Cache is called Invalidation. Please note that most of the settings in the Cloudimage Admin panel requires Invalidation of the Image Cache after saving of any changes. Without this Invalidation, the CDN servers still keep the old version of the image files in their cache and the changes can't take action. In the Cloudimage documentation and the Admin panel exist many Reminders that prompt you to invalidate your old Image Cache when it is needed.
    Screenshot_2021-09-07_at_18.07.10.pngScreenshot_2021-09-07_at_18.05.38.png

In case of any doubts or questions about the set up of the Caching Interval, you can open a ticket to our Support team. Please include:

- your token;

- short description of your usecase (what is your website about, how often the images need to be refreshed, what is the average "life span" of an image in this website)

- short description of the problem (if the ticket is about reporting of an issue)

We will check your usecase and will provide an answer in a timely manner.

The official Cloudimage documentation for the Caching Interval can be found here.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.