You are here

public function GeocoderThrottle::__construct in Geocoder 8.3

Constructs a new throttle service.

The storage must be instantiated once and reused to work correctly.

File

src/GeocoderThrottle.php, line 25

Class

GeocoderThrottle
Provides a throttle mecanism for geocoder requests.

Namespace

Drupal\geocoder

Code

public function __construct() {
  $this->throttle = new LeakyBucket();

  // TODO For now, we use a per-process storage, which means that requests
  // sent at the same time by another process (like another user on the
  // website) will be throttled separately, so that the actual limit of the
  // provider could still be reached.
  // In common use cases, it's not a problem because bulk geocoding is handled
  // by one process, such as a drush command.
  // But it could be improved by using a more shared and persistent storage
  // that would fit more use cases.
  $this->throttle
    ->setStorage(new Process());
}