From 095000cfaec61c62dfac28d5a4c9620343b61ad9 Mon Sep 17 00:00:00 2001 From: Andrew Dinmore Date: Thu, 26 Feb 2026 15:57:32 +0000 Subject: [PATCH] Hash group/stream name for creation log item key --- src/Handler/CloudWatch.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Handler/CloudWatch.php b/src/Handler/CloudWatch.php index aa3d8f1..347f7d4 100755 --- a/src/Handler/CloudWatch.php +++ b/src/Handler/CloudWatch.php @@ -334,8 +334,11 @@ private function initializeGroup(): void { // Check if a PSR-6 cache pool is available if ($this->cacheItemPool !== null) { + // Create a cache key based on the group name, use hash to avoid invalid characters + $cacheKey = 'cwh-group-' . hash('crc32c', $this->group); + // Attempt to retrieve the cached state for the current log group - $cacheItem = $this->cacheItemPool->getItem($this->group); + $cacheItem = $this->cacheItemPool->getItem($cacheKey); // If the group is already cached, skip further initialization if ($cacheItem->isHit()) { @@ -377,10 +380,7 @@ private function initializeGroup(): void } // Check if a cache pool is configured - if ($this->cacheItemPool !== null) { - // Retrieve or create a cache item for the current log group - $cacheItem = $this->cacheItemPool->getItem($this->group); - + if (isset($cacheItem)) { // Mark the log group as initialized/existing $cacheItem->set(true); @@ -399,8 +399,11 @@ private function initializeStream(): void { // Check if a PSR-6 cache pool is configured if ($this->cacheItemPool !== null) { + // Create a cache key based on the stream name, use hash to avoid invalid characters + $cacheKey = 'cwh-stream-' . hash('crc32c', $this->stream); + // Attempt to retrieve the cached state for the current log stream - $cacheItem = $this->cacheItemPool->getItem($this->stream); + $cacheItem = $this->cacheItemPool->getItem($cacheKey); // If the stream is already known to exist in cache, skip initialization if ($cacheItem->isHit()) { @@ -435,10 +438,7 @@ private function initializeStream(): void } // If a cache pool is available, mark the log stream as initialized - if ($this->cacheItemPool !== null) { - // Create/retrieve a cache item using the stream name as the key - $cacheItem = $this->cacheItemPool->getItem($this->stream); - + if (isset($cacheItem)) { // Set value to true to indicate the stream exists $cacheItem->set(true);