Skip to content

[12.x] Allow Unit & Backed enums for cache stores#55172

Closed
michaeldyrynda wants to merge 3 commits intolaravel:12.xfrom
michaeldyrynda:feature/support-cache-backed-enum
Closed

[12.x] Allow Unit & Backed enums for cache stores#55172
michaeldyrynda wants to merge 3 commits intolaravel:12.xfrom
michaeldyrynda:feature/support-cache-backed-enum

Conversation

@michaeldyrynda
Copy link
Copy Markdown
Contributor

This PR enables us to use BackedEnum and UnitEnum values for cache keys, where previously only strings were possible.

In doing so, we can mitigate against typos when working with cache keys.

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@michaeldyrynda
Copy link
Copy Markdown
Contributor Author

Opened this as draft so as to get feedback on whether test approach 1 (updating existing tests) or 2 (effectively duplicating the tests) is the preferred method.

I'll implement for the other cache stores once a direction is chosen.

Comment thread src/Illuminate/Cache/ResolvesKeyName.php Outdated
* Retrieve an item from the cache by key.
*
* @param string $key
* @param \BackedEnum|\UnitEnum|string $key
Copy link
Copy Markdown
Contributor

@shaedrich shaedrich Mar 26, 2025

Choose a reason for hiding this comment

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

Btw, BackedEnum is a UnitEnum, so I'd say, technically, UnitEnum would suffice

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whilst technically true, the use of both in docblocks is consistent with similar behaviour elsewhere in the framework.

@michaeldyrynda michaeldyrynda force-pushed the feature/support-cache-backed-enum branch from 678cdaa to 5073b37 Compare March 26, 2025 23:06
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.

3 participants