一键导入
drupal-caching
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
HTMX in Drupal 11.3+ core — the Htmx PHP fluent builder, dynamic forms with swapOob, partial routes with _htmx_route, response headers, and Drupal.behaviors integration. Use when building interactive UI without full-page reloads using Drupal's native HTMX support.
DDEV local development expertise. Use when working with DDEV projects, containers, configuration, or troubleshooting DDEV environments.
Custom Docker Compose local development patterns. Use when working with Docker-based local environments, container configuration, or troubleshooting Docker setups.
Drupal access control — permissions.yml, access callbacks, AccessResult, custom access checkers, and entity access.
Drupal Composer management — requiring modules, updates, patches via composer-patches, and version constraints.
Drupal configuration management with Drush — import/export config, preview config changes before applying (e.g., seeing what would change without importing), config splits, and environment syncing.
| name | drupal-caching |
| description | Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays. |
Always add cache metadata. Missing cache metadata causes stale content.
$build['content'] = [
'#markup' => $output,
'#cache' => [
'tags' => ['node:' . $node->id(), 'node_list'],
'contexts' => ['user.permissions', 'url.query_args'],
'max-age' => Cache::PERMANENT,
],
];
| Tag | Invalidated when |
|---|---|
node:{nid} | Node {nid} is saved/deleted |
node_list | Any node is created or deleted |
user:{uid} | User {uid} is saved |
taxonomy_term:{tid} | Term {tid} is saved |
config:{name} | Config object {name} is saved |
| Context | Varies by |
|---|---|
user.permissions | User's permissions (prefer over user) |
user.roles | User's roles |
url.path | URL path |
url.query_args | Query parameters |
languages | Current language |
$cached = $this->cacheBackend->get('my_module:my_key');
if ($cached !== FALSE) {
return $cached->data;
}
$this->cacheBackend->set('my_module:my_key', $data, Cache::PERMANENT, ['node_list']);
$this->cacheBackend->set('my_module:my_key', $data, \Drupal::time()->getRequestTime() + 3600, ['node_list']);
$this->cacheBackend->delete('my_module:my_key');
Cache::invalidateTags(['node:123', 'node_list']);
use Drupal\Core\Cache\CacheBackendInterface;
public function __construct(
private readonly CacheBackendInterface $cacheBackend,
) {}
# services.yml
my_module.my_service:
arguments: ['@cache.default']
$build['#cache']['tags'] = Cache::mergeTags(
$build['#cache']['tags'] ?? [],
$node->getCacheTags()
);