Skip to content

Drupal 8/9

The Peakhour Purge module transparently enables full page caching on the Peakhour EDGE for Drupal 8/9. Once installed, Drupal will issue Cache Tag headers on page responses, along with Cache Control headers for cacheable pages. The module extends the Drupal Purge module to send Peakhour flush by tag requests when content is changed in the Drupal Admin.

Supported Features#

  • Integrated with Drupal Purge
  • Fully supports flush by cache tags
  • Improve cache behaviour by skipping caching on session cookie rather than varying on cookie

Requirements#

  • Drupal 8 or greater
  • PHP 7.2 or greater (Drupal 8.8 requirement)

Download#

The module can be obtained from the Peakhour Purge module page on the Drupal website.

Installation#

Prerequisites#

You will need a Peakhour account to be able to utilise this extension. If you don't already have one you can sign up here, installation of the extension does not automatically create an account for you.

All new signups get a free trial. Once you have your account the only other change you need to make to activate our acceleration and web application firewall is a DNS change. Do not enable the module until you have successfully configured your domain behind the Peakhour service.

1. Install the module:#

The Peakhour Purge module requires the Drupal Purge module, make sure you install Purge first using composer:

composer require drupal/purge

1.1 To install via composer#

composer require drupal/peakhour_purge

1.2 To install manually#

Unzip the module under the Drupal /modules/contrib directory

2. Enable the modules.#

  1. In the drupal admin go to the Extend tab and scroll down to the PURGE section.
  2. Tick all the items under the Purge heading.
  3. Then, under PURGE - PROCESSORS choose how you want cache invalidation to be performed, using a cron job, or for every request.
  4. Then under PURGE - QUEUERS, tick Core tags queuer
  5. Finally, under PURGE - REVERSE PROXIES & CDNS tick Peakhour Purge
  6. Then scroll to the bottom and press Install

3. Configure the module#

Click on Configuration in the top level menu, then on Performance under the Development section. On the resulting page choose a cache TTL (1 year is recommended) from the dropdown under Browser and proxy cache maximum age and click Save Configuration

Then click on the Purge tab. Then click on the Add Purger button. Peakhour should be the only option, but if you do have multiple Purge modules installed, then select Peakhour and click Add.

Then click on the down arror next to Peakhour and click 'Configure', a pop up will be displayed with the following fields:

  • 'Enabled'
  • 'Your Domain Name' = The domain name as entered in your Peakhour account.
  • 'API Key' = Your API Key, available under your Peakhour account -> API Keys
  • 'API URL' = The API endpoint for Peakhour, should default to https://www.peakhour.io/api/v1/

Fill in these fields (including ticking Enabled) and click 'Save Configuration'

By default, Drupal adds a Vary: Cookie header to the server response so that users that log in will skip the cache. However, this can result in very poor cache hit rates if you use third parties that set their own cookies, eg Google Analytics, an AWS load balancer, etc. Peakhour allows you to skip the cache if a given Cookie is set, so we can remove the Vary and set the skip to allow for much higher hit rates.

To remove the Vary: Cookie header, go to your settings.php under your Drupal installation. This is usually under:

DRUPAL_HOME/web/sites/default

You may have to copy the default.settings.php to settings.php if you don't have a settings.php in the directory. Open the file and uncomment the

# $settings['omit_vary_cookie'] = TRUE;

line and make sure it is set to true.

If you have done step 4 and removed the Vary: Cookie header you will also want to configure Peakhour to skip its full page cache if a Drupal session cookie is set. To do this log in to the Peakhour admin, administer your domain, then choose 'Edge Rules' from the left menu.

Add a new rule with the following:

  • Rule Name = Skip Cache
  • Filter = not http.request.uri.path contains "."
  • Skip Cookie = SESS*

IMPORTANT This example assumes you are using a standard Drupal 8/9 setup where page URLs don't have periods in them and don't end in /.

Congratulations! You've successfully installed and configured the module. Drupal will add a Cache Control header which will enable Peakhour to automatically start caching full pages. When content is changed Drupal will issue a flush request(s) with the list of tags that have changed. You can view the flush requests under your Peakhour account. Log in, administer your domain, then click on the 'Flush Logs' left menu item. secure as it can be!

As always if you need help then Contact Us and we'll gladly assist.