Skip to content

Fix: Gracefully handle cache drivers that do not support tagging - #75

Merged
alies-dev merged 8 commits into
mainfrom
fix/handle-cache-drivers-without-tagging-support
Apr 3, 2026
Merged

Fix: Gracefully handle cache drivers that do not support tagging#75
alies-dev merged 8 commits into
mainfrom
fix/handle-cache-drivers-without-tagging-support

Conversation

@alies-dev

Copy link
Copy Markdown
Member

Context

When the default cache driver does not support tagging (e.g. file, database), but cache_tags is configured (which is the default), the geoip:clear command fails with a misleading error. Additionally, there is no indication to the developer that their tag configuration is being silently ignored at runtime.

This is the same issue reported in Torann#255, but addressed more robustly at the code level rather than with a config-level workaround.

Solution

  • Type the Cache constructor $tags parameter as array with a @param list<string> annotation, replacing the untyped parameter
  • Normalize cache_tags config in GeoIP constructor using array_values((array) ...) so null or missing values safely become an empty array instead of causing errors
  • Log a warning when cache tags are configured but the active driver does not support tagging, so developers can discover the mismatch through logs
  • Replace the hardcoded driver list (['file', 'database']) in Clear::isSupported() with a dynamic supportsTags() check that covers all current and future non-tagging drivers
  • Improve the geoip:clear error message to explain why selective clearing is unavailable
  • Add a test that uses the file cache driver to genuinely exercise the fallback path
  • Update the config comment to document the auto-fallback behavior and the option to set cache_tags to null

The default config enables cache tags, but drivers like "file" or
"database" do not support tagging. This change:

- Types the Cache constructor $tags parameter as array and normalises
  the config value in GeoIP so null/missing values become an empty array
- Replaces the hardcoded driver list in Clear command with a dynamic
  supportsTags() check that covers all current and future drivers
- Updates config comment to explain auto-fallback behaviour
- Adds a test covering tagged-cache construction on a non-tagging driver

Addresses the same issue as Torann#255.
…sage

- Fix test to use file cache driver (which genuinely lacks tag support)
  instead of array driver, so the fallback path is actually exercised
- Log a warning in GeoIP constructor when cache tags are configured but
  the active driver does not support tagging
- Improve geoip:clear error message to explain why selective clearing
  is unavailable
@alies-dev alies-dev self-assigned this Apr 3, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves the handling of cache tags by allowing them to be automatically ignored if the active cache driver does not support tagging. Key changes include updating the Cache constructor type-hints, refining the Clear command's support check to use the supportsTags() method, and adding a warning log when tags are configured but unsupported. A concern was raised regarding the warning log in GeoIP.php, as it may cause log flooding if the service is instantiated frequently in environments without tag support.

Comment thread src/GeoIP.php
Comment on lines +69 to +71
if ($cacheTags !== [] && !$cache->supportsTags()) {
$this->logger->warning('GeoIP: cache tags are configured but the active cache driver does not support tagging. Tags will be ignored.');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The warning message is logged every time the GeoIP service is instantiated if the cache driver does not support tags. This could lead to log flooding in production environments. Consider using a more rate-limited approach or logging this only once per request/process lifecycle.

alies-dev and others added 6 commits April 3, 2026 13:14
composer.json already requires ^8.3, so 8.2 builds are unnecessary.
The Docker image (oskarstark/php-cs-fixer-ga) does not have access to
the project's composer dependencies, causing a fatal error because the
custom IxDFCodingStandard\PhpCsFixer\Config class is not found. Use the
locally installed php-cs-fixer from vendor/bin instead.
- Replace Docker-based php-cs-fixer with composer scripts
- Add Rector auto-fix step alongside php-cs-fixer
- Add fork-safe dual-job setup: auto-fix for internal PRs, dry-run
  check for fork PRs
- Add rector:dry and cs:check composer scripts for CI dry-run jobs
@alies-dev
alies-dev merged commit e64c668 into main Apr 3, 2026
27 of 28 checks passed
@alies-dev
alies-dev deleted the fix/handle-cache-drivers-without-tagging-support branch April 3, 2026 11:23
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