You are here

public function AcquiaCloudPurger::routeTypeToMethod in Acquia Purge 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

src/Plugin/Purge/Purger/AcquiaCloudPurger.php, line 500

Class

AcquiaCloudPurger
Acquia Cloud.

Namespace

Drupal\acquia_purge\Plugin\Purge\Purger

Code

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