Action plugin for Page Cache Kill Switch

Created on 10 December 2024, 3 months ago

Problem/Motivation

Drupal core has a "page_cache_kill_switch" that is sometimes necessary to prevent certain pages from being cached. The ECA Cache module has an action to set the max-age to 0, but nothing to use the Page Cache Kill Switch.

Both of these are sometimes necessary.

Steps to reproduce

Proposed resolution

Implement a page cache kill switch action in ECA Cache submodule.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @freelock
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    I'm a bit rushed at the moment, but I created an action module for a client to get this done:

    
    namespace Drupal\eca_cache\Plugin\Action;
    
    use Drupal\Core\Access\AccessResultInterface;
    use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\Session\AccountInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    use Drupal\eca\Plugin\Action\ConfigurableActionBase;
    
    /**
     * Provides a Page Cache Kill Switch action.
     *
     * @Action(
     *   id = "page_cache_kill_switch",
     *   label = @Translation("Page Cache Kill Switch"),
     *   description = @Translation("Kill the page cache for this page")
     * )
     */
    final class PageCacheKillSwitch extends ConfigurableActionBase {
    
      /**
       * {@inheritdoc}
       */
      public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
        $self = parent::create(
          $container,
          $configuration,
          $plugin_id,
          $plugin_definition
        );
        $self->KillSwitch = $container->get('page_cache_kill_switch');
        return $self;
      }
    
      /**
       * {@inheritdoc}
       */
      public function execute(): void {
        $this->KillSwitch->trigger();
      }
    
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    New action plugin -- this is working on a site in a custom module -- only difference is updating the namespace to eca_cache and updating the plugin id.

  • Pipeline finished with Failed
    3 months ago
    Total: 473s
    #364761
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thanks @freelock, this looks like a great enhancement. Before a detailed review, it would be good to fixed the broken tests first.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Ping

  • Pipeline finished with Failed
    about 1 month ago
    Total: 346s
    #399608
  • Pipeline finished with Failed
    about 1 month ago
    Total: 460s
    #399612
  • Pipeline finished with Failed
    about 1 month ago
    Total: 221s
    #399620
  • Pipeline finished with Failed
    about 1 month ago
    Total: 270s
    #399621
  • Pipeline finished with Success
    about 1 month ago
    Total: 1043s
    #399625
  • Pipeline finished with Failed
    about 1 month ago
    Total: 331s
    #399640
  • Pipeline finished with Failed
    about 1 month ago
    Total: 280s
    #399641
  • Pipeline finished with Failed
    about 1 month ago
    Total: 218s
    #399643
  • Pipeline finished with Failed
    about 1 month ago
    Total: 334s
    #399646
  • Pipeline finished with Success
    about 1 month ago
    Total: 903s
    #399647
  • Pipeline finished with Skipped
    about 1 month ago
    #401813
  • Pipeline finished with Success
    about 1 month ago
    Total: 840s
    #401963
  • Pipeline finished with Success
    25 days ago
    Total: 1474s
    #415677
  • Status changed to Needs work 6 days ago
  • πŸ‡ΈπŸ‡°Slovakia coaston

    Hi @freelock, any progress? This sounds good.

  • Pipeline finished with Success
    4 days ago
    Total: 226s
    #435475
Production build 0.71.5 2024