Package for Laravel framework -
overrides remember method of Laravel Cache using lock mechanism
to avoid multiply generation of the same data (as a result of
race condition) when cache becomes invalid.
- PHP >= 7.4
- Laravel >= 7.0
Install (or update) package via composer:
composer require enikeishik/cachewithlockMake sure autoload will be changed:
composer dump-autoloadPublish package via artisan:
php artisan vendor:publish --provider="Enikeishik\CacheWithLock\ServiceProvider"This command copy configuration file into corresponding project folder.
Package service provider contains an extend call to override Laravel Cache class.
So there is no need to make any changes in code.
Overriding can be disabled in package configuration.
Without overriding Laravel Cache use CacheWithLock facade:
use CacheWithLock;
...
$value = CacheWithLock::remember(...);
...