Skip to content

Commit

Permalink
Don't try to store already stored key
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Aug 26, 2024
1 parent 397fd45 commit 4925e86
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Behaviours/CachedOnCDN.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

trait CachedOnCDN
{
protected array $edgeFlushCachedAttributes = [];

public function invalidateCDNCache(Entity|Model $object): void
{
if (!$this->edgeFlushIsEnabled() || !$this->invalidationsAreEnabled()) {
Expand Down Expand Up @@ -48,8 +50,12 @@ public function getCDNCacheTag(string $key = null, string|null $type = null): st
: '';
}

public function cacheModelOnCDN(Model $model, string $key = null, array $allowedKeys = []): void
public function cacheModelOnCDN(Model $model, string $key, array $allowedKeys = []): void
{
if (!$this->edgeFlushKeyWasAlreadyAdded($key)) {
return;
}

if (!$this->edgeFlushIsEnabled()) {
return;
}
Expand All @@ -66,4 +72,13 @@ public function invalidationsAreEnabled(): bool
{
return Helpers::configBool('edge-flush.enabled.services.invalidation', false);
}

public function edgeFlushKeyWasAlreadyAdded(string $key): bool
{
$added = !in_array($key, $this->edgeFlushCachedAttributes);

$this->edgeFlushCachedAttributes[$key] = $key;

return $added;
}
}

0 comments on commit 4925e86

Please sign in to comment.