refactor(cache): refactor cache configuration pattern#7594
Merged
limingxinleo merged 8 commits intohyperf:3.2from Nov 4, 2025
Merged
refactor(cache): refactor cache configuration pattern#7594limingxinleo merged 8 commits intohyperf:3.2from
limingxinleo merged 8 commits intohyperf:3.2from
Conversation
This refactors the cache configuration to follow Laravel's convention with a stores-based pattern, improving flexibility and consistency with other frameworks.
Changes:
- Restructured cache configuration with 'default' driver selection and 'stores' array
- Added support for CACHE_DRIVER environment variable
- Updated CacheManager::getDriver() to accept null and read from default config
- Changed config path from 'cache.{$name}' to 'cache.stores.{$name}'
- Simplified CacheManager::call() method signature with proper type hints
- Updated test configurations to match new structure
Benefits:
- More intuitive configuration structure
- Better alignment with Laravel's caching conventions
- Easier to manage multiple cache drivers
- Improved environment-based driver selection
Simplified the description for cache configuration changes in the changelog by removing reference to Laravel-style stores pattern.
41035d2 to
2e7c430
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the cache configuration structure to be more consistent with other components like logging. The main change introduces a stores array to hold cache driver configurations, with a top-level default key that specifies which store to use by default. Backward compatibility is maintained through automatic migration logic in CacheManager.
- Introduced a new configuration structure with
defaultkey pointing to a store name andstoresarray containing driver configurations - Added backward compatibility logic to automatically migrate old configuration format
- Updated tests and documentation to reflect the new structure
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/cache/src/CacheManager.php | Added backward compatibility migration logic and updated driver lookup to use cache.stores.* path |
| src/cache/tests/Cases/RedisDriverTest.php | Updated test configuration to use new stores structure |
| src/cache/publish/cache.php | Migrated publish configuration to new format with environment variable support |
| CHANGELOG-3.2.md | Added documentation of the breaking change with before/after examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
limingxinleo
approved these changes
Nov 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the cache configuration structure to follow Laravel's convention with a stores-based pattern, improving flexibility and consistency with other modern PHP frameworks.
Changes
Configuration Structure (
src/cache/publish/cache.php)defaultkey for driver selection with environment variable support (CACHE_DRIVER)storesarrayCacheManager Updates (
src/cache/src/CacheManager.php)getDriver(?string $name = null)to accept null parameter and read from default configcache.{$name}tocache.stores.{$name}call()method with proper type hints and simplified parameter signatureTest Updates (
src/cache/tests/Cases/RedisDriverTest.php)Benefits
CACHE_DRIVERenvironment variableMigration Guide
Users need to update their
config/autoload/cache.phpfile from:To:
Test Plan