Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[6.x] Add LazyCollection@remember method #30443
This PR adds a
$users = User::cursor()->remember(); // No query has been executed yet. $users->all(); // All values have been pulled from the DB. $users->all(); // We did not hit the DB again. We got the users from `remember`'s cache.
$users = User::cursor()->remember(); // No query has been executed yet. $users->take(5)->all(); // The query has been executed, and the first 5 users have been streamed from the DB. $users->take(20)->all(); // The first 5 users came from the cache. The rest continued the stream from the DB.
This PR includes extensive tests ensuring that it's fully lazy, and that two simultaneous runners don't step on each other's toes.
@tobiasthaden I think that would lead to a lot of confusion, and in my case I would probably write fresh more than remember with the current implementation.
@36864 It's an already existing method on the collection so that's not a good solution in my opinion.
@narwy That's already an [existing method])https://laravel.com/docs/6.x/collections#method-partition)
I like the remember, I don't see the reason to use different names in different parts in the software, just like we don't use different methods for dispatching a job or an event.
I want cache to remember something: