Skip to content
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

Improve Lock->block method #52349

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Improve Lock->block method #52349

merged 2 commits into from
Aug 1, 2024

Conversation

RedmarBakker
Copy link
Contributor

Small improvement to the block method of the default cache driver. While developing my own cache layer for Laravel, I figured that that the block method on a cache lock didn't quite cover the work it should do in my opinion. This is because the while loop, which attempts to acquire the lock every 250 miliseconds, has a heavy ordering problem of executing the usleep and the timeout test. While failing to acquire the lock, it should immediately check if there will be a timeout after the following nap. Currently, if the method will end up in a timeout, it will unnecessarily execute another usleep.

The Lock will now use the now() method to do time management instead of using the InteractsWithTime trait. I don't know if that is out of line with the idea of the code, but it sure works without any issues.

Currently i am using this own block implementation, but would love to work with the improvement within the framework itself.

And, thanks for the amazing framework!

Chears!

@RedmarBakker RedmarBakker changed the title Improve lock->block method to only wait longer if timeout won't be re… Improve Lock-block method to only wait longer if timeout won't be re… Aug 1, 2024
@RedmarBakker RedmarBakker changed the title Improve Lock-block method to only wait longer if timeout won't be re… Improve Lock->block method to only wait longer if timeout won't be re… Aug 1, 2024
@driesvints driesvints changed the title Improve Lock->block method to only wait longer if timeout won't be re… Improve Lock->block method Aug 1, 2024
@taylorotwell taylorotwell merged commit fd9e84e into laravel:11.x Aug 1, 2024
29 checks passed
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.

2 participants