Skip to content

Let 0 turn off the cache expiry and the cache size limit - #6453

Open
ekamran wants to merge 1 commit into
wp-cli:mainfrom
ekamran:shifteq/cache-limits-accept-zero
Open

ekamran wants to merge 1 commit into
wp-cli:mainfrom
ekamran:shifteq/cache-limits-accept-zero

Conversation

@ekamran

@ekamran ekamran commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6452

WP_CLI::get_cache() read both cache limits with (int) $value ?: default, so WP_CLI_CACHE_EXPIRY=0 and WP_CLI_CACHE_MAX_SIZE=0 became the 180-day and 300 MB defaults. FileCache treats 0 as no limit, and a negative value already turned a limit off, so 0 was the one value that could not.

The default is now used only when the value casts to 0 and is not a number. So a number that casts to 0, such as 0 or 0.5, turns the limit off. Empty and non-numeric values keep the defaults, and values that cast to a non-zero number are read as before. Values set under env: in wp-cli.yml are covered too, since they are read through the same get_env_or_config().

Testing

  • New Behat outline in features/cli-cache.feature reads the limits the cache is built with, for unset, empty, 0, 7200/1048576, -1 and abc. A second outline makes a cached file 200 days old, forces the cleanup, and checks that WP_CLI_CACHE_EXPIRY=0 keeps it while the default removes it. The two 0 cases fail on main and pass with the fix. The other cases pass on both.
  • All 14 scenarios in features/cli-cache.feature and the three cache scenarios in features/config.feature pass. phpcs is clean on the changed file.
  • With the real command and a forced cleanup: WP_CLI_CACHE_EXPIRY=0 keeps a 200-day-old file and WP_CLI_CACHE_MAX_SIZE=0 keeps a 301 MB file, set either way (environment or wp-cli.yml). Before the fix both files were removed. An empty value and abc still use the defaults.

Use of AI

AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: tracing the bug, writing the tests, drafting the change, and reviewing it. I reviewed the reasoning and test results, and I take responsibility for the contribution.

Summary by CodeRabbit

  • Bug Fixes
    • Cache expiry and maximum-size settings now correctly honor numeric values, including 0 and -1.
    • Empty or nonnumeric settings use the default limits of six months and 300 MiB.
    • Expired cache files are removed according to the configured expiry; setting expiry to 0 keeps them from expiring.

`WP_CLI::get_cache()` read both limits with `(int) $value ?: default`, so `WP_CLI_CACHE_EXPIRY=0` and `WP_CLI_CACHE_MAX_SIZE=0` became the 180-day and 300 MB defaults, although `FileCache` treats 0 as no limit. The default is now used only when the value casts to 0 and is not a number, so a number that casts to 0, such as `0` or `0.5`, turns the limit off. Empty and non-numeric values keep the defaults, and values that cast to a non-zero number are read as before.
@ekamran
ekamran requested a review from a team as a code owner November 4, 2026 16:37
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes

The cache settings now preserve numeric values, including zero. Nonnumeric values use the existing defaults. Feature scenarios check settings and cleanup behavior.

Cache limit configuration

Layer / File(s) Summary
Parse cache limits and verify zero handling
php/class-wp-cli.php, features/cli-cache.feature
WP_CLI::get_cache() now casts numeric settings and uses defaults for nonnumeric settings. Scenarios check unset, empty, numeric, and nonnumeric values, plus whether cleanup removes an expired file with the default expiry or retains it when expiry is zero.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: schlessera

Merge Risk: Minimal · up to 2fe4c

Zero disables the corresponding cache limit. No merge-blocking risk was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: allowing 0 to disable cache expiry and the cache size limit.
Linked Issues check Passed Issue #6452 requires numeric values that cast to zero to disable cache expiry or size limits, while empty and non-numeric values retain defaults. WP_CLI::get_cache() now uses is_numeric() with the…
Out of Scope Changes check Passed The reviewed changes are limited to cache-limit handling in php/class-wp-cli.php and Behat coverage in features/cli-cache.feature. The test changes directly verify the requirements in issue #6452.…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #6452 requires numeric values that cast to zero to disable cache expiry or size limits, while empty and non-numeric values retain defaults. WP_CLI::get_cache() now uses is_numeric() with the cast result before selecting defaults. This passes 0, 0.5, and negative numeric values to FileCache after integer conversion, and retains defaults for empty and non-numeric values. The implementation reads both values through Utils\get_env_or_config(), so env: configuration uses the same path. The feature outline verifies unset, empty, zero, non-zero, negative, and non-numeric values. The cleanup scenario verifies that expiry 0 keeps an old file while the default removes it.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to cache-limit handling in php/class-wp-cli.php and Behat coverage in features/cli-cache.feature. The test changes directly verify the requirements in issue #6452. No unrelated behavior or unrelated files are evidenced.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38385ffc-73c8-41d3-93ff-879459ee13a1
Commits

Reviewing files that changed from the base of the PR and between aafc2a8 and 2fe4c4c.

Files selected for processing: 2
  • features/cli-cache.feature
  • php/class-wp-cli.php

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions github-actions Bot added bug command:cli-cache Related to 'cli cache' command labels Nov 4, 2026
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:cli-cache Related to 'cli cache' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP_CLI_CACHE_EXPIRY=0 and WP_CLI_CACHE_MAX_SIZE=0 fall back to the defaults

1 participant