Skip to content
Snippets Groups Projects

Issue #3450070: Implement post cache webhook event

Merged Christian Foidl requested to merge 3450070-implement-post-cache into 1.0.x
2 files
+ 57
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 50
0
<?php
namespace Drupal\nextjs\Event;
use Psr\Http\Message\ResponseInterface;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Event when a cache webhook was sent.
*/
class CacheWebhookResponseEvent extends Event {
const EVENT_NAME = 'nextjs.cache_webhook_response';
/**
* Construct new event.
*/
public function __construct(
protected string $url,
protected ResponseInterface $response,
protected \DateTime $dateTime,
) {}
/**
* If webhook was processed successfully.
*/
public function isSuccess(): bool {
return $this->response->getStatusCode() === 200;
}
/**
* Get HTTP response.
*/
public function getResponse(): ResponseInterface {
return $this->response;
}
/**
* Get time when webhook was processed by Next.js.
*
* This is useful, e.g. if you need to make sure the cache
* revalidation is fully propagated (add 300ms to this time).
*
* @see https://vercel.com/docs/infrastructure/data-cache#revalidation-behavior
*/
public function getProcessedTime(): \DateTime {
return $this->dateTime;
}
}
Loading