Skip to content

Commit

Permalink
Functional tag/path/everything purger.
Browse files Browse the repository at this point in the history
  • Loading branch information
stooit committed Apr 19, 2024
1 parent f48040e commit b5f0ac9
Show file tree
Hide file tree
Showing 10 changed files with 803 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/quant_api/src/Client/QuantClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,44 @@ public function search() {
return FALSE;
}

/**
* {@inheritdoc}
*/
public function purgePath(string $path) : array {
$response = $this->client->post($this->endpoint . '/purge', [
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Quant-Url' => $path,
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
]);

return json_decode($response->getBody(), TRUE);
}

/**
* {@inheritdoc}
*/
public function purgeTags(array $tags) : array {

$response = $this->client->post($this->endpoint . '/purge', [
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Cache-Keys' => implode(' ', $tags),
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
]);

return json_decode($response->getBody(), TRUE);

}

/**
* {@inheritdoc}
*/
Expand Down
28 changes: 28 additions & 0 deletions modules/quant_api/src/Client/QuantClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ public function search();
*/
public function send(array $data) : array;

/**
* Sends a purge payload (path based) to the API.
*
* @param string $path
* The path to purge.
*
* @return array
* Return array of response data.
*
* @throws \Drupal\quant_api\Exception\InvalidPayload
* @throws \Drupal\quant_api\Exception\InvalidResposne
*/
public function purgePath(string $path) : array;

/**
* Sends a purge payload (tags based) to the API.
*
* @param array $tags
* The array of tags to purge.
*
* @return array
* Return array of response data.
*
* @throws \Drupal\quant_api\Exception\InvalidPayload
* @throws \Drupal\quant_api\Exception\InvalidResposne
*/
public function purgeTags(array $tags) : array;

/**
* Send a file to the API.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
quant_purge_header:
type: mapping
label: 'Quant Header'
mapping:
field:
type: string
translatable: false
value:
type: string
translatable: false
44 changes: 44 additions & 0 deletions modules/quant_purger/config/schema/quant_purger.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,47 @@ quant_purger.settings:
type: string
label: 'String that cannot be present in a fully qualified URL.'
translatable: false

quant_purger.settings.*:
type: config_entity
label: 'Section Purger'
mapping:

#
# Instance metadata:
#
id:
type: string
translatable: false
name:
type: string
translatable: false
invalidationtype:
type: string
translatable: false

#
# Performance settings:
#
runtime_measurement:
type: boolean
translatable: false
timeout:
type: float
translatable: false
connect_timeout:
type: float
translatable: false
cooldown_time:
type: float
translatable: false
max_requests:
type: integer
translatable: false

#
# Success resolution:
#
http_errors:
type: boolean
translatable: false
115 changes: 115 additions & 0 deletions modules/quant_purger/src/Entity/QuantPurgeSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Drupal\quant_purger\Entity;

use Drupal\purge\Plugin\Purge\Purger\PurgerSettingsBase;
use Drupal\purge\Plugin\Purge\Purger\PurgerSettingsInterface;

/**
* Defines the QuantCDN purger settings entity.
*
* @ConfigEntityType(
* id = "quantpurgersettings",
* label = @Translation("QuantCDN"),
* config_prefix = "settings",
* static_cache = TRUE,
* entity_keys = {"id" = "id"},
* config_export = {
* "id",
* "label",
* "description",
* "name",
* "invalidationtype",
* "runtime_measurement",
* "timeout",
* "connect_timeout",
* "cooldown_time",
* "max_requests",
* "http_errors"
* },
* )
*/
class QuantPurgeSettings extends PurgerSettingsBase implements PurgerSettingsInterface {

/**
* Instance metadata.
*/

/**
* The readable name of this purger.
*
* @var string
*/
public $name = '';

/**
* The invalidation plugin ID that this purger invalidates.
*
* @var string
*/
public $invalidationtype = 'tag';

/**
* Runtime measurement.
*
* When FALSE, dynamic capacity calculation will be disabled and based upon
* the connect_timeout and timeout settings.
*
* @var bool
*/
// @phpcs:ignore
public $runtime_measurement = TRUE;

/**
* The timeout of the request in seconds.
*
* @var float
*/
public $timeout = 1.0;

/**
* The number of seconds to wait while trying to connect to a server.
*
* @var float
*/
// @phpcs:ignore
public $connect_timeout = 1.0;

/**
* Cooldown time.
*
* Number of seconds to wait after one or more invalidations took place (so
* that other purgers get fresh content).'
*
* @var float
*/
// @phpcs:ignore
public $cooldown_time = 0.0;

/**
* Maximum requests.
*
* Maximum number of HTTP requests that can be made during Drupal's execution
* lifetime. Usually PHP resource restraints lower this value dynamically, but
* can be met at the CLI.
*
* @var int
*/
// @phpcs:ignore
public $max_requests = 250;

/**
* Success resolution.
*/

/**
* Whether 4xx and 5xx responses need to be treated as failures or not.
*
* @var bool
*
* @see http://docs.guzzlephp.org/en/latest/request-options.html#http-errors
*/
// @phpcs:ignore
public $http_errors = TRUE;

}
19 changes: 19 additions & 0 deletions modules/quant_purger/src/Form/QuantPurgeForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Drupal\quant_purger\Form;

/**
* Configuration form for the HTTP Bundled Purger.
*/
class QuantPurgeForm extends QuantPurgeFormBase {

/**
* The token group names this purger supports replacing tokens for.
*
* @var string[]
*
* @see purge_tokens_token_info()
*/
protected $tokenGroups = ['invalidation'];

}
Loading

0 comments on commit b5f0ac9

Please sign in to comment.