You are here

public function CloudFlarePurger::routeTypeToMethod in CloudFlare 8

Route certain type of invalidations to other methods.

Simple purgers supporting just one type - for example 'tag' - will get that specific type offered in ::invalidate(). However, when supporting multiple types it might be useful to have PurgersService sort and route these for you to the methods you specify. The expected signature and method behavior is equal to \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate.

One note of warning: depending on the implementation specifics of a plugin, sorting and dispatching types to different code paths can be less efficient compared to external platforms allowing you to mix and send everyhing in one single batch. Therefore, consult the API of the platform your plugin supports to decide what the most efficient implementation will be.

A simple implementation will look like this:


  public function routeTypeToMethod($type) {
    $methods = [
      'path' => 'invalidatePaths',
      'tag'  => 'invalidateTags',
      'url'  => 'invalidateUrls',
    ];
    return isset($methods[$type]) ? $methods[$type] : 'invalidate';
  }

Parameters

string $type: The type of invalidation(s) about to be offered to the purger.

Return value

string The PHP method name called on the purger with a $invalidations parameter.

Overrides PurgerBase::routeTypeToMethod

File

modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php, line 120

Class

CloudFlarePurger
CloudFlare purger.

Namespace

Drupal\cloudflarepurger\Plugin\Purge\Purger

Code

public function routeTypeToMethod($type) {
  $methods = [
    'everything' => 'invalidate',
    'tag' => 'invalidate',
    'url' => 'invalidate',
  ];
  return isset($methods[$type]) ? $methods[$type] : 'invalidate';
}