Skip to content

Commit

Permalink
dont use locks when using dynamo
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 7, 2023
1 parent 5deb049 commit 965d77e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Illuminate/Console/Scheduling/CacheEventMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Console\Scheduling;

use Illuminate\Cache\DynamoDbStore;
use Illuminate\Contracts\Cache\Factory as Cache;
use Illuminate\Contracts\Cache\LockProvider;

Expand Down Expand Up @@ -40,7 +41,7 @@ public function __construct(Cache $cache)
*/
public function create(Event $event)
{
if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) {
return $this->cache->store($this->store)->getStore()
->lock($event->mutexName(), $event->expiresAt * 60)
->acquire();
Expand All @@ -59,7 +60,7 @@ public function create(Event $event)
*/
public function exists(Event $event)
{
if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) {
return ! $this->cache->store($this->store)->getStore()
->lock($event->mutexName(), $event->expiresAt * 60)
->get(fn () => true);
Expand All @@ -76,7 +77,7 @@ public function exists(Event $event)
*/
public function forget(Event $event)
{
if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) {
$this->cache->store($this->store)->getStore()
->lock($event->mutexName(), $event->expiresAt * 60)
->forceRelease();
Expand All @@ -87,6 +88,17 @@ public function forget(Event $event)
$this->cache->store($this->store)->forget($event->mutexName());
}

/**
* Determine if the given store should use locks for cache event mutexes.
*
* @param \Illuminate\Contracts\Cache\Store $store
* @return bool
*/
protected function shouldUseLocks($store)
{
return $store instanceof LockProvider && ! $store instanceof DynamoDbStore;
}

/**
* Specify the cache store that should be used.
*
Expand Down

0 comments on commit 965d77e

Please sign in to comment.