CacheRouterRebuildSubscriber.php 851 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Drupal\Core\EventSubscriber;
  3. use Drupal\Core\Cache\Cache;
  4. use Drupal\Core\Routing\RoutingEvents;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. /**
  7. * Clear cache tags when the router is rebuilt.
  8. */
  9. class CacheRouterRebuildSubscriber implements EventSubscriberInterface {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function onRouterFinished() {
  14. // Requested URLs that formerly gave a 403/404 may now be valid.
  15. // Also invalidate all cached routing as well as every HTTP response.
  16. Cache::invalidateTags(['4xx-response', 'route_match', 'http_response']);
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function getSubscribedEvents() {
  22. $events = [];
  23. // Act only when the router rebuild is finished.
  24. $events[RoutingEvents::FINISHED][] = ['onRouterFinished', 200];
  25. return $events;
  26. }
  27. }