Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

drupal-cache-maxageDrupal 缓存最大使用期限

Agent Skill

drupal-cache-maxage 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

333

周安装

14

GitHub Stars

1

下载量

116
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:drupal-cache-maxage(Drupal 缓存最大使用期限)
来源仓库:https://github.com/sparkfabrik/sf-awesome-copilot
仓库路径:skills/drupal-cache-maxage
安装命令:
npx skills add https://github.com/sparkfabrik/sf-awesome-copilot --skill drupal-cache-maxage
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/sparkfabrik/sf-awesome-copilot --skill drupal-cache-maxage

简介

控制基于时间的缓存有效期设置规则。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

  • 理解 Page Cache 与 Dynamic Page Cache 的差异。
  • 掌握 max-age 值在渲染树中的传递逻辑。
  • 适用于外部 API 数据缓存和实时内容更新场景。
  • drupal-cache-maxage 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Drupal Cache Max-Age

Max-age defines time-based cache validity in seconds.

When to Use

  • Caching external API data with known refresh intervals
  • Time-sensitive content (countdowns, live scores)
  • Understanding why anonymous pages stay cached
  • Debugging UNCACHEABLE responses

Critical Behavior

Page Cache ignores max-age - Only uses tags for invalidation. Dynamic Page Cache respects max-age - max-age:0 causes UNCACHEABLE. Max-age bubbles up - Minimum value wins across render tree.

Max-Age Values

ValueMeaning
0Uncacheable - DANGER: bubbles up!
Cache::PERMANENT (-1)Forever until tag invalidation
36001 hour
864001 day

Examples

Example 1: External API Data

Input: "I fetch weather data from an API, how do I cache it for 15 minutes?"

Output:

$build = [
  '#markup' => $this->weatherService->getCurrentWeather(),
  '#cache' => [
    'max-age' => 900, // 15 minutes
    'tags' => ['weather:current'],
  ],
];

Example 2: Cache Forever Until Invalidation

Input: "My content only changes when the entity is edited"

Output:

use Drupal\Core\Cache\Cache;

$build = [
  '#markup' => $node->getTitle(),
  '#cache' => [
    'max-age' => Cache::PERMANENT, // -1, forever
    'tags' => $node->getCacheTags(), // Invalidates on node save
  ],
];

Example 3: Time-Sensitive Countdown

Input: "I show a countdown to an event, how do I handle cache?"

Output:

public function buildCountdown(): array {
  $event_time = strtotime('2024-12-31 23:59:59');
  $remaining = $event_time - time();

  return [
    '#markup' => $this->formatCountdown($remaining),
    '#cache' => [
      // Cache for 1 minute or until event, whichever is shorter
      'max-age' => $remaining > 0 ? min($remaining, 60) : 0,
    ],
  ];
}

Example 4: max-age:0 Causes Page UNCACHEABLE

Input: "Why does X-Drupal-Dynamic-Cache show UNCACHEABLE?"

Output:

// PROBLEM: This makes entire page uncacheable
$build['timestamp'] = [
  '#markup' => time(),
  '#cache' => ['max-age' => 0], // Bubbles up to page!
];

// SOLUTION: Use lazy builder to isolate uncacheable content
$build['timestamp'] = [
  '#lazy_builder' => ['my_module.lazy:renderTimestamp', []],
  '#create_placeholder' => TRUE,
];

Example 5: Page Cache Ignores max-age

Input: "I set max-age to 300 but anonymous users still see old content after 5 minutes"

Output:

// max-age:300 does NOT work for Page Cache!
// Page Cache only respects cache tags, not max-age

// Option 1: Use cache tags and invalidate when data changes
Cache::invalidateTags(['my_module:data']);

// Option 2: Disable Page Cache for this route
// In your_module.routing.yml:
my_module.dynamic_page:
  path: '/dynamic'
  defaults:
    _controller: '\Drupal\my_module\Controller::page'
  options:
    no_cache: TRUE

// Option 3: Kill Page Cache programmatically
\Drupal::service('page_cache_kill_switch')->trigger();

Example 6: Finding max-age:0 Source

Input: "How do I find what's setting max-age to 0?"

Output:

// Method 1: Xdebug conditional breakpoint
// File: core/lib/Drupal/Core/Cache/Cache.php
// Method: mergeMaxAges()
// Condition: $a === 0 || $b === 0

// Method 2: Temporary debug logging
// Add to Cache::mergeMaxAges() temporarily:
if ($a === 0 || $b === 0) {
  \Drupal::logger('cache_debug')->warning(
    'max-age:0 at: @trace',
    ['@trace' => json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5))]
  );
}

Example 7: Browser Cache-Control Headers

Input: "How do I control browser caching separately from Drupal cache?"

Output:

// Site-wide: Admin > Config > Development > Performance
// Sets Cache-Control header for anonymous pages

// Per-response in controller:
use Symfony\Component\HttpFoundation\Response;

public function myPage(): Response {
  $build = ['#markup' => 'Content'];
  $html = \Drupal::service('renderer')->renderRoot($build);

  $response = new Response($html);
  $response->headers->set('Cache-Control', 'public, max-age=3600');

  return $response;
}

Max-Age Bubbling Behavior

// Parent: max-age 3600
$build = [
  '#markup' => 'Parent',
  '#cache' => ['max-age' => 3600],
];

// Child: max-age 0
$build['child'] = [
  '#markup' => 'Child',
  '#cache' => ['max-age' => 0],
];

// Result: entire $build has effective max-age: 0
// The minimum always wins!

Common Mistakes

MistakeImpactSolution
max-age:0 in render arrayEntire page uncacheableUse lazy builder
Relying on max-age for Page CachePages never expireUse cache tags + invalidation
Short max-age on stable contentUnnecessary re-rendersUse tags, set PERMANENT
Forgetting bubblingChild max-age:0 breaks parentAudit all render elements

Debugging

# Check max-age header
curl -sI https://site.com/ | grep -i 'cache-control\|x-drupal-cache-max-age'

# Clear render cache and test
drush cache:clear render
curl -sI https://site.com/node/1

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.65%
按下载量换算43

Claude

30.06%
按下载量换算35

Cursor

20.07%
按下载量换算23

Gemini CLI

8.78%
按下载量换算10

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills