Skip to content

Release 2.3.2 - #5

Merged
LoveDoLove merged 22 commits into
mainfrom
lovedolove
Jul 4, 2026
Merged

LoveDoLove merged 22 commits into
mainfrom
lovedolove

Conversation

@LoveDoLove

Copy link
Copy Markdown
Owner
  • Add AI Agent memory system
  • Add cache statistics feature (hits/misses, cached URLs, bypass reasons, admin dashboard)
  • Add cache statistics feature and update documentation
  • Fix syntax error in core.php and finalize cache statistics feature
  • feat: implement cache statistics tracking and dashboardAdded hit/miss tracking logic and admin UI to monitor cache performance, resolving the undefined function fatal error.
  • Revert "feat: implement cache statistics tracking and dashboardAdded hit/miss tracking logic and admin UI to monitor cache performance, resolving the undefined function fatal error."
  • Release 2.2.0 — Cache Statistics Dashboard
  • chore(website): migrate from npm to pnpm
  • Release 2.3.0 — Production-grade Rate Limiting Optimization
  • Release 2.3.1 — Cache Mechanism Core Optimization Phase 1
  • Release 2.3.2 — Auto-Configuration Wizard
  • fix: auto-config API calls missing Authorization header
  • fix: remove nonexistent zone setting API calls, fix DNS proxy filtering
  • fix: production-grade rewrite of DNS proxy + Page Rule error handling
  • fix: extract nested CF error meta.messages + remove priority from Page Rule payload
  • fix: dump full CF errors array to reveal actual Page Rule validation reason
  • fix: add priority=50 to Page Rule payload, test 2-action first
  • fix: also dump CF messages array in Page Rule error
  • fix: replace edge_cache_ttl=0 with explicit_cache_control=on in Page Rule
  • feat: plan-aware configuration via API
  • fix: handle UUID plan IDs from Cloudflare API (partner/reseller plans)
  • docs: comprehensive codebase scan, update AGENTS.md and MEMORY.md with accurate stats

LoveDoLove and others added 22 commits June 27, 2026 15:43
- Create AGENTS.md: AI agent identity definition and guidelines
- Create MEMORY.md: Long-term memory for user preferences and project context
- Create memory/tasks.md: Cross-conversation task tracking
- Create memory/2026-06-27.md: Daily AI work log

Core features documented:
- Edge HTML caching with Cloudflare API
- Automatic cache purging on content changes
- API token authentication support
- Rate limiting (1000 req/5min)
- Multi post type support
- 6 developer hooks and filters
- Advanced admin UI and comprehensive logging

Cloudflare Smart Cache WordPress plugin v2.1.0
… tracking logic and admin UI to monitor cache performance, resolving the undefined function fatal error.
…hit/miss tracking logic and admin UI to monitor cache performance, resolving the undefined function fatal error."

This reverts commit f72787c.
- Add 8 cache statistics functions to core.php (hit/miss counters, URL tracking, bypass reasons, stats getters)

- Wire bypass counters into all 7 branches of cf_smart_cache_set_edge_headers()

- Implement cf_smart_cache_display_cache_status() in admin.php (configuration status, performance table, bypass reasons, recent cached URLs)

- Fix Fatal Error: undefined function cf_smart_cache_display_cache_status()

- Fix function name mismatch: record_bypass -> record_bypass_reason

- Bump plugin version 2.1.0 -> 2.2.0

- Update AGENTS.md with cache statistics section and changelog

- Update MEMORY.md with v2.2.0 entry and full function inventory

- Document Cache Statistics Dashboard in website/index, features, usage, faq

- Update memory/tasks.md and add memory/2026-06-28.md
- Remove website/package-lock.json (npm)

- Add website/pnpm-lock.yaml (pnpm 9.x lockfile)

- Add website/pnpm-workspace.yaml restricting esbuild builds

- Switch workflow from 'npm install' to 'pnpm install'

Lockfile resolution changes (vitepress 1.6.4 + transitive deps).
- Sliding-window governor with adaptive limit (auto-tunes on 429)
- Token Bucket rate limiter for Purge API (per Cloudflare plan)
- Exponential Backoff with ±20% jitter and Retry-After header support
- HTTP Executor retry layer (3 attempts, 429/5xx/network error handling)
- Debounced purge queue (2s merge window, 100 URL hard cap)
- Admin UI: Rate Limit dashboard + 5 configurable settings fields
- All wp_remote_* calls migrated to http_request wrapper
- Hook endpoints migrated to enqueue_purge for debounced batching
- Backward-compatible check_rate_limit() wrapper retained
- Removed legacy purge0/1/2 system (15+ redundant hook bindings removed)
- Added dynamic TTL with stale-while-revalidate/stale-if-error directives
- Added content-aware TTL function (cf_smart_cache_get_ttl)
- Added dual-layer purge URL caching (wp_cache + post meta hash)
- Added cf_smart_cache_purge_urls_hash() for cross-request cache validation
- Added clean handler for theme/profile/menu change events
- All syntax validated, no legacy purge references remain
One-click detection, application, backup, and rollback of Cloudflare settings:

- Detect: cf_smart_cache_get_config_status() returns full status of
  Page Rule, Origin Cache Control, DNS Proxy, and backup state
- Page Rule: Creates/updates cache_everything rule with
  edge_cache_ttl=0 and explicit_cache_control=on (single rule, all actions)
- Origin Cache Control: PATCH /settings/explicit_cache_control → on
- DNS Proxy: Batch PATCH /dns_records/{id} → proxied=true, supports
  root-only or all strategy via dropdown
- Backup: Up to 3 snapshots stored in wp_options, auto-backup before
  apply/rollback, rule-ID-precise restore
- Admin UI: Status table with colored badges + checkboxes + strategy
  selectors + Backup/Apply/Rollback buttons
- 14 new core functions + 2 new admin functions, all syntax validated
Root cause: All auto-config functions (get_page_rules, apply_page_rule,
get_zone_setting, apply_zone_setting, get_dns_records, apply_dns_proxy,
delete_page_rule, backup_config, restore_backup) called
cf_smart_cache_http_request() without setting the Authorization:
Bearer header, causing every Cloudflare API call to return 401/403.

Fix:
1. Inject Authorization header in cf_smart_cache_http_request() when
   caller hasn't explicitly set it — all CF API calls need auth
2. Surface actual Cloudflare API error messages in WP_Error responses
   instead of generic 'Invalid Page Rules response' / 'Failed to set'
Three production bugs found after auth-header fix surfaced real errors:

1. explicit_cache_control is a Page Rule action, NOT a zone-level setting
   - Removed cf_smart_cache_apply_zone_setting('explicit_cache_control')
     from Apply handler — handled by Page Rule triple-action payload
   - Removed cf_smart_cache_get_zone_setting('explicit_cache_control')
     from backup/restore — always fails with 'Unrecognized zone setting'
   - get_config_status now derives Origin CC status from Page Rule
     actions instead of zone setting API
   - Admin UI checkbox changed to informational (disabled + checked)

2. DNS records API call used &name={domain} filter that was too strict
   - Removed name= filter from GET dns_records URL — fetch all records
   - PHP-side root-vs-all strategy filtering still applies after fetch
   - Fixes '0 records updated' when zone domain differs from record names

3. Page Rule requires 'Page Rules: Edit' token permission
   - User must add this scope to their Cloudflare API token
Systemic issues addressed after real-API testing revealed 3 latent bugs:

1. cf_smart_cache_get_dns_records() - pagination + name normalization
   - Added pagination loop (per_page=100, page=N) to handle zones with >100 records
   - Added _name_normalized field (rtrim trailing dot) for reliable client-side matching
   - Explains '0 records updated': root filter compared raw API names (with dots) vs zone_name (without)

2. cf_smart_cache_apply_dns_proxy() - structured return
   - Returns {updated, skipped, errors, detail} instead of raw result array
   - Admin handler shows granular status like '3 updated, 2 already proxied'

3. Apply handler - actionable error messages
   - Page Rule 403 appends clear instruction to add Page Rules: Edit permission
   - DNS result differentiates no_records vs already_proxied vs updated/skipped/errors
   - Root filter uses rtrim on BOTH sides + handles @ convention for apex records
…e Rule payload

1. 'See messages for details' errors from Cloudflare now surface
   nested meta.messages for debugging (e.g. 'explicit_cache_control
   not available on your plan')
2. Removed priority=1 from Page Rule POST/PUT payload to avoid
   validation conflicts with existing rules (auto-assign)
…Rule

Root cause (from CF API messages): '.settings[1].value: Your plan
allows for a minimum TTL of 7200' — edge_cache_ttl=0 (Respect Existing
Headers) is not accepted on Free/Pro plans.

The fix: remove edge_cache_ttl entirely and add back
explicit_cache_control=on. Together with cache_level=cache_everything,
this is sufficient — explicit_cache_control=on tells Cloudflare to
respect the origin's Cache-Control headers (including our s-maxage=300),
making edge_cache_ttl redundant. Also verified against official CF API
docs that the payload format is correct (no priority needed, CF auto-
assigns).
Adds cf_smart_cache_get_zone_plan() and cf_smart_cache_get_plan_limits()
to eliminate hardcoded assumption about which plan the zone is on.

Changes:
- GET /zones/{zone_id} to fetch actual plan id, cached in transient 24h
- Plan limits lookup table: max_page_rules, edge_cache_ttl_min per plan
- get_config_status now uses API plan instead of rate_limit_cf_plan setting
- Status includes page_rules_used, page_rule_available, plan_limits
- Apply handler checks available Page Rule slots before attempting create
- Zone transient cleared on settings save
- uninstall.php cleans up the new transient
cf_smart_cache_get_zone_plan() assumed plan.id is always a standard
name (free/pro/business/enterprise), but partner/reseller plans have
UUID plan IDs. Falls back to plan.name for display and defaults to
'free' limits for unknown plan types.
Copilot AI review requested due to automatic review settings July 4, 2026 17:57
@LoveDoLove LoveDoLove changed the title lovedolove Release 2.3.2 Jul 4, 2026
@LoveDoLove
LoveDoLove merged commit 7f5e13d into main Jul 4, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Cloudflare Smart Cache plugin and its documentation to reflect and support newer functionality (cache statistics dashboard, rate limiting improvements, and an auto-configuration wizard), while also adding/refreshing the repository’s AI memory/task tracking and migrating the docs site lockfile to pnpm.

Changes:

  • Extends plugin core/admin with cache statistics, rate limiting + purge queue behavior, and auto-configuration/plan-aware Cloudflare setup.
  • Updates documentation pages to describe the cache statistics dashboard and version/status.
  • Adds/updates AI memory and task-tracking markdown files; adds pnpm lock/workspace files for the docs site.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
website/usage.md Documents the Cache Statistics Dashboard usage and core functions.
website/pnpm-workspace.yaml Adds pnpm workspace configuration for docs site (currently invalid schema).
website/pnpm-lock.yaml Adds pnpm lockfile for the docs site dependencies.
website/index.md Updates docs homepage with “current version” and feature highlight.
website/features.md Updates feature list and cache statistics section (introduced BOM + typo).
website/faq.md Adds FAQ entries for the cache statistics dashboard behavior/TTL/perf.
memory/tasks.md Adds task tracking content (contains future-dated metadata).
memory/2026-07-05.md Adds AI work log for July 5 (future-dated vs PR metadata).
memory/2026-06-28.md Adds AI work log for cache statistics implementation.
memory/2026-06-27.md Adds AI work log for initial analysis + cache stats design notes.
MEMORY.md Adds/refreshes repository “AI Memory” snapshot (future-dated metadata).
cf-smart-cache/uninstall.php Ensures new transients are removed on uninstall.
cf-smart-cache/includes/core.php Major core changes: dynamic TTL, cache stats, rate limiting, purge queue, auto-config + plan awareness.
cf-smart-cache/cf-smart-cache.php Bumps plugin version + clears new transients on activation/deactivation.
cf-smart-cache/admin/admin.php Adds rate limiting settings, cache stats UI, and auto-config UI/handlers.
AGENTS.md Adds/refreshes agent identity doc (contains broken quoted fragment + future date).
Files not reviewed (2)
  • website/package-lock.json: Generated file
  • website/pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,4 +1,4 @@
<?php
<?php
@@ -1,4 +1,4 @@
<?php
<?php
Comment on lines +645 to +648
if ( count( $queue ) >= 100 ) {
cf_smart_cache_flush_purge_queue();
return;
}
{
if (is_user_logged_in()) {
cf_smart_cache_add_security_headers();
cf_smart_cache_record_bypass_reason('logged-in');
}
if (is_admin() || $GLOBALS['pagenow'] === 'wp-login.php') {
cf_smart_cache_add_security_headers();
cf_smart_cache_record_bypass_reason('admin');
Comment on lines +1 to +2
allowBuilds:
esbuild: false
Comment thread website/features.md
@@ -1,4 +1,4 @@
---
---
Comment thread website/features.md
- **Bypass Reasons** — Count of each bypass reason (logged-in, admin, ajax, rest, preview, password, woocommerce), sorted descending.
- **Recent Cached URLs** — Up to 10 most recent cached URLs with timestamps.

Counters are recorded in `cf-smart-cache_set_edge_headers()`: the 7 bypass branches call `cf_smart_cache_record_bypass_reason()` and the cacheable branch calls `cf_smart_cache_increment_hit()`. No external dependencies are required to render the dashboard.
Comment thread AGENTS.md
Comment on lines +546 to +548
**最後更新**:2026-07-05
**版本**:2.3.2
" - 2026-06-27: 实现了缓存统计功能(命中/未命中计数器、已缓存 URL "列表、绕过原因追踪、管理员统计仪表盘)。
Comment on lines +1310 to +1314
if ( is_wp_error( $response ) ) {
$errors++;
} else {
$updated++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants