Last active
May 6, 2023 14:18
-
-
Save labboy0276/687764dd8a6254656faf4e992daa756a to your computer and use it in GitHub Desktop.
Drupal 8/9/10 Core Cache Rebuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "drupal/YOUR_MODULE", | |
"type": "drupal-module", | |
"description": "YOUR_MODULE System Tweaks", | |
"extra": { | |
"drush": { | |
"services": { | |
"drush.services.yml": "^9 || ^10 || ^11" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
YOUR_MODULE.command_one: | |
class: \Drupal\YOUR_MODULE\Commands\RebuildCache | |
tags: | |
- { name: drush.command } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\YOUR_MODULE\Commands; | |
use Drush\Commands\DrushCommands; | |
/** | |
* Rebuild the cache mechanism via drush. | |
*/ | |
class RebuildCache extends DrushCommands { | |
/** | |
* Rebuild the cache mechanism via drush. | |
* | |
* @command custom:cache-rebuild | |
* @aliases ccrb | |
* @usage custom:cache-rebuild | |
*/ | |
public function cacheRebuild() { | |
// Flush all the caches. | |
drupal_flush_all_caches(); | |
// Handles clearing the kernel containers. | |
$kernel = \Drupal::service('kernel'); | |
$kernel->invalidateContainer(); | |
$kernel->rebuildContainer(); | |
// Disable recording of cached pages. | |
\Drupal::service('page_cache_kill_switch')->trigger(); | |
// APCU Clear if it exists. | |
if (function_exists('apcu_clear_cache')) { | |
apcu_clear_cache(); | |
} | |
$this->output()->writeln('Core Cache rebuild complete.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment