Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Oct 9, 2023
1 parent 6db352d commit 8b71bca
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Recorders/CacheInteractions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Closure;
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Config\Repository;
Expand Down Expand Up @@ -51,29 +52,31 @@ public function record(CacheHit|CacheMissed $event): ?Entry
return null;
}

$key = $event->key;

return new Entry($this->table, [
'date' => $now->toDateTimeString(),
'hit' => $event instanceof CacheHit,
'key' => fn () => $this->normalize($key),
'key' => $this->normalizeKey($event),
'user_id' => $this->pulse->authenticatedUserIdResolver(),
]);
}

/**
* Normalize the cache key.
*/
protected function normalize(string $key): string
protected function normalizeKey(CacheHit|CacheMissed $event): Closure
{
foreach ($this->config->get('pulse.cache_keys') as $pattern => $replacement) {
$normalized = preg_replace($pattern, $replacement, $key, count: $count);
$key = $event->key;

if ($count > 0 && $normalized !== null) {
return $normalized;
return function () use ($key) {
foreach ($this->config->get('pulse.cache_keys') as $pattern => $replacement) {
$normalized = preg_replace($pattern, $replacement, $key, count: $count);

if ($count > 0 && $normalized !== null) {
return $normalized;
}
}
}

return $key;
return $key;
};
}
}

0 comments on commit 8b71bca

Please sign in to comment.