Fastly provides a Soft Purge feature that allows you to mark content as outdated (stale) instead of permanently purging and thereby deleting it from Fastly's caches. Objects invalidated with Soft Purge will be treated as outdated (stale) while Fastly fetches a new version from origin.

To implement Soft Purge, add a Fastly-Soft-Purge request header (such as Fastly-Soft-Purge: 1) to any single URL or key-based purge.

For more, see https://docs.fastly.com/guides/purging/soft-purges

It would be great if the module gave the site admin a choice to use soft instead of immediate purging.

Comments

alexmoreno created an issue. See original summary.

alexmoreno’s picture

StatusFileSize
new726 bytes

This is just a port of: https://www.drupal.org/project/fastly/issues/2683775

Attach a first attempt, very simple just for the sake of testing the concept. To merge it will need at least an option to enable/disable the features, for example via setting variables with drush.

alexmoreno’s picture

StatusFileSize
new5.08 KB

Adding an option to enable/disable the feature

alexmoreno’s picture

alexmoreno’s picture

Just enable from /admin/config/development/performance/purge/softpurge

If you have Purge UI enabled it will also show you a warning message

alexmoreno’s picture

a status message was invalidating cache, so I've removed that. See new patch attached.

alexmoreno’s picture

wim leers’s picture

Status: Active » Needs work
  1. +++ b/acquia_purge.routing.yml
    @@ -0,0 +1,7 @@
    +    _permission: 'Enable/Disable Soft Purge in Fastly'
    

    🤔 This is a really weird permission name.

    It doesn't follow the pattern of Drupal core's permissions.

  2. +++ b/src/AcquiaPlatformCdn/FastlyBackend.php
    @@ -241,11 +241,19 @@ class FastlyBackend extends BackendBase implements BackendInterface {
    +    $soft_purge = \Drupal::config('acquia_purge.soft_purge')->get('acquia_purge_soft_purge');
    

    Should be injected.

  3. +++ b/src/AcquiaPlatformCdn/FastlyBackend.php
    @@ -241,11 +241,19 @@ class FastlyBackend extends BackendBase implements BackendInterface {
    +	if($soft_purge) {
    +	  \Drupal::logger('fastly')->notice('Soft purging fastly caches');
    +	  $opt['headers']['Fastly-Soft-Purge'] = 1;
    +	}
    +
    +	return $opt;
    

    🐛 Leading tabs instead spaces.

  4. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +namespace Drupal\acquia_purge\Form;
    +use Drupal\Core\Form\ConfigFormBase;
    

    🤓 Needs extra \n in between.

  5. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    + * Configure logging behavior.
    

    🐛 Copy/pasted stale comment.

  6. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +  final public function __construct() {
    

    🤔 Why final?

    Why even have a constructor if there is nothing in there?

  7. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +      '#prefix' => '<p>',
    +      '#suffix' => '</p>',
    +      '#markup' => $this->t("Fastly provides a Soft Purge feature that allows you to mark content as outdated (stale) instead of permanently purging and thereby deleting it from Fastly's caches. Objects invalidated with Soft Purge will be treated as outdated (stale) while Fastly fetches a new version from origin. For more information visit <a href='https://docs.fastly.com/en/guides/soft-purges'>https://docs.fastly.com/en/guides/soft-purges</a>"),
    

    Huh? Why not:

    '#markup' => '<p>'. $this->t(…) .'</p>'
    

    ?

  8. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +    $config = $this->config('acquia_purge.soft_purge');
    +    $soft_purge = $config->get('acquia_purge_soft_purge');
    

    🤔

    So … the config is

    acquia_purge.soft_purge.acquia_purge_soft_purge
    

    ?

    That looks very very weird.

  9. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +    $form['acquia_purge_soft_purge'] = array(
    

    🤔 So … this is mixing old style PHP array syntax in with the new? Let's make this look sane.

  10. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +      '#title' => $this
    +        ->t('Enable Fastly Soft Purge'),
    

    🐛 Poorly placed line break.

  11. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +    $messenger = \Drupal::messenger();
    

    🐛

    First: this should've been injected.

    Second: this is already available to you thanks to the base class!

  12. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +      $messenger->addMessage('Fastly soft purge enabled', $messenger::TYPE_WARNING);
    

    🤔 Why not use addWarning()?

  13. +++ b/src/Form/SoftPurgeConfigForm.php
    @@ -0,0 +1,88 @@
    +    $this->config('acquia_purge.soft_purge')
    +      ->set('acquia_purge_soft_purge', $enabled)
    

    🐛

    $enabled is not guaranteed to be a boolean.

    And … config schema is missing.