diff --git a/cacheflush.services.yml b/cacheflush.services.yml
index 86b9a9b..8e2da07 100644
--- a/cacheflush.services.yml
+++ b/cacheflush.services.yml
@@ -1,3 +1,4 @@
 services:
   cacheflush.api:
     class: 'Drupal\cacheflush\Controller\CacheflushApi'
+    arguments: ['@service_container', '@messenger', '@extension.list.module']
diff --git a/src/Controller/CacheflushApi.php b/src/Controller/CacheflushApi.php
index 685c82d..4825ff7 100644
--- a/src/Controller/CacheflushApi.php
+++ b/src/Controller/CacheflushApi.php
@@ -9,6 +9,7 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
 use Drupal\cacheflush_entity\Entity\CacheflushEntity;
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\PhpStorage\PhpStorageFactory;
+use Drupal\Core\Extension\ModuleExtensionList;
 
 /**
  * Returns responses for Cacheflush routes.
@@ -29,6 +30,13 @@ class CacheflushApi extends ControllerBase {
    */
   protected $messenger;
 
+  /**
+   * The module extension list.
+   *
+   * @var \Drupal\Core\Extension\ModuleExtensionList
+   */
+  protected $moduleExtensionList;
+
   /**
    * CacheflushApi constructor.
    *
@@ -36,10 +44,13 @@ class CacheflushApi extends ControllerBase {
    *   The Drupal container.
    * @param \Drupal\Core\Messenger\MessengerInterface $messenger
    *   The messenger service.
+   * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
+   *   The module extension list.
    */
-  public function __construct(ContainerInterface $container, MessengerInterface $messenger) {
+  public function __construct(ContainerInterface $container, MessengerInterface $messenger, ModuleExtensionList $extension_list_module) {
     $this->container = $container;
     $this->messenger = $messenger;
+    $this->moduleExtensionList = $extension_list_module;
   }
 
   /**
@@ -48,7 +59,8 @@ class CacheflushApi extends ControllerBase {
   public static function create(ContainerInterface $container) {
     return new static(
       $container,
-      $container->get('messenger')
+      $container->get('messenger'),
+      $container->get('extension.list.module')
     );
   }
 
@@ -184,7 +196,7 @@ class CacheflushApi extends ControllerBase {
     $this->container->get('kernel')->invalidateContainer();
 
     // Rebuild module and theme data.
-    $module_data = system_rebuild_module_data();
+    $module_data = $this->moduleExtensionList->reset()->getList();
     /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
     $theme_handler = $this->container->get('theme_handler');
     $theme_handler->refreshInfo();
