-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor(cache): refactor cache configuration pattern #7594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(cache): refactor cache configuration pattern #7594
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.
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 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.
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