Direkt zum Inhalt

Devbits

Kleine Code-Schnipsel aus unserem Alltag mit Drupal, PHP und DevOps: Problem, Lösung, Code.

26.03.2026 | Pascal Crott

Clear plugin manager cache

You want to clear a specific plugin cache.

\Drupal::service('plugin_id.manager')->clearCachedDefinitions();
// Clear entity_type plugin cache.
\Drupal::entityTypeManager()->clearCachedDefinitions();

Issue:

You want to clear a specific plugin cache.

Solution:

Use the snippet provided.

13.11.2025 | Nikolas Kopp

Clear APC & Opcache

You need to clear APC and Opcache, e.g. for debugging purposes.

<?php

apcu_clear_cache();
opcache_reset();

Issue:

You need to clear APC and Opcache, e.g. for debugging purposes.

Solution:

drush php:script clear_cache 

This snippet clears APCu and Opcache. Put it into the docroot. Execute from browser, not from CLI.

See the drush documentation for more info.

13.11.2025 | Nikolas Kopp

Cache Debugging for Render Elements

You need to get to know the caching settings for render elements.

  renderer.config:
    required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions']
    auto_placeholder_conditions:
      max-age: 0
      contexts: ['session', 'user']
      tags: []
    debug: true # The debug setting

Issue:

You need to get to know the caching settings for render elements.

Solution:

Drupal 9.5 introduced a debug setting for the renderer configuration to display cache information for each rendered element (see also: https://www.drupal.org/node/3162480).

13.11.2025 | Michael Ebert

Warm your Drupal caches after a cache clear

We all know the problem that a Drupal site may be loading slowly after a cache clear.

tags:
  - { name: cache_prewarmable }
/**
  * Implements \Drupal\Core\PreWarm\PreWarmableInterface.
  */
public function preWarm(): void {
  $this->getDefinitions();
}

Issue:

We all know the problem that a Drupal site may be loading slowly after a cache clear.

Prerequisites:

  • Drush ≥ 13.5
  • Drupal ≥ 11.2

Solution:

There is a new prewarm API introduced in Drupal 11.2. This allows you to add a `cache_prewarmable` tag to your services and implement a preWarm method. If you are using Drush version 13.5 or newer, it will automatically call a `cache:warm` as last step when doing a `drush deploy`.

This will only warm cache cache items that are used to build most pages, plugins and registries, but not render caching or anywhere like that. 

Furter informations can be found here: