Skip to content

Conversation

@cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Aug 25, 2025

I needed a way to extract the data from the ArrayStore inside of a test. While I could get the value of many records and adjust the Carbon timestamp to see when they expire, this doesn't seem particularly developer-friendly.

@cosmastech cosmastech marked this pull request as draft August 25, 2025 15:52
@cosmastech cosmastech marked this pull request as ready for review August 25, 2025 18:49
@henzeb
Copy link
Contributor

henzeb commented Aug 26, 2025

You can use Carbon::setTestNow to see if it expires. No need to extract the data. But if you truly must, I doubt this will be accepted, use closures with binding.

@cosmastech
Copy link
Contributor Author

cosmastech commented Aug 26, 2025

You can use Carbon::setTestNow to see if it expires. No need to extract the data. But if you truly must, I doubt this will be accepted, use closures with binding.

I bound the ArrayStore to a Closure, as you mentioned. But that doesn't feel particularly ergonomic, especially for a driver that I assume is primarily used in tests. 🤷

@henzeb
Copy link
Contributor

henzeb commented Aug 26, 2025

You can use Carbon::setTestNow to see if it expires. No need to extract the data. But if you truly must, I doubt this will be accepted, use closures with binding.

I bound the ArrayStore to a Closure, as you mentioned. But that doesn't feel particularly ergonomic, especially for a driver that I assume is primarily used in tests. 🤷

True, but generally you don't test laravel, you test your own input. In this case TTL. Using Carbon setTestNow is the best way. And if that doesn't suit your needs, this is the next best. They are not going to add this unless everyone really benefits from it and not just because you say so.

@cosmastech cosmastech changed the title [12.x] ArrayStore::getStorage() [12.x] ArrayStore::all() Aug 26, 2025
@taylorotwell taylorotwell merged commit a308230 into laravel:12.x Aug 26, 2025
60 checks passed
@cosmastech cosmastech deleted the patch-18 branch August 26, 2025 13:36
@AhmedAlaa4611
Copy link
Contributor

Hello @cosmastech

After this PR, the new Cache::all() method only works when the cache driver is set to array. Other drivers like file or database don’t implement all(). Was this limitation intentional, or is it an oversight and we should expect consistent behavior across all drivers?

@cosmastech
Copy link
Contributor Author

Hello @cosmastech

After this PR, the new Cache::all() method only works when the cache driver is set to array. Other drivers like file or database don’t implement all(). Was this limitation intentional, or is it an oversight and we should expect consistent behavior across all drivers?

The use-case I envisioned here was to simplify testing when using the ArrayStore for the cache driver. I personally did not intend to add this to all drivers.

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.

4 participants