Configuring for CDN caching
CloudFront is the CDN of choice for Skpr, and it will respect the configuration of your application. By not configuring your application correctly, the CDN will inherit the configuration and will not cache the requests made. This will result in lost performance, higher vulnerability to distributed denial of service attacks, and it will come with a cost factor.
As a product owner, it is in your best interest to make sure the minimal configuration is done to allow the CDN to cache
requests made to the application. All that is necessary is to ensure the header named Max-Age
has a sensible value,
and we recommend this be set to 21600 or higher.
Implementation
Drupal 9+
Go to /admin/config/development/performance
, set your maximum cache age and submit the form.
And don't forget to export your configuration and commit it, so that you know the change can't be reverted unexpectedly.
Drupal 7
You can use drush to set the required variables for Drupal 7 to configure caching. We however would recommend setting
these values to hard-coded values in settings.php
.
$conf['cache'] = 1;
$conf['page_cache_maximum_age'] = 21600;
Testing
These methods will ensure that Drupal will set the Max-Age
header on all of its responses, and it will provide you
with a way to test that your CDN is responding with a cached copy of the content. By looking for the x-cache
response
header, you can identify if CloudFront is serving a cached copy of your content. The first time should be a MISS
, but
running it once more you should receive a HIT
.
$ curl https://prod.mysite.skpr.live | grep "x-cache"
x-cache: Hit from cloudfront