From ad56616309700fcd09543126227307b28110e03b Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Wed, 20 Apr 2022 20:01:45 +0200 Subject: [PATCH] Reduce size of Unique ID Prefix used for the Cell Collection when "in memory" (reduces the per-cell memory overhead, while still retaining a unique prefix to ensure no clash between worksheet collections). External cache (where multiple threads may be accessing the same cache with different workeets) still uses the same length and entropy in the prefix as before --- src/PhpSpreadsheet/Collection/Cells.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Collection/Cells.php b/src/PhpSpreadsheet/Collection/Cells.php index e3d81cb4..3ffb8a4f 100644 --- a/src/PhpSpreadsheet/Collection/Cells.php +++ b/src/PhpSpreadsheet/Collection/Cells.php @@ -6,6 +6,7 @@ use Generator; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Psr\SimpleCache\CacheInterface; @@ -298,7 +299,9 @@ class Cells */ private function getUniqueID() { - return uniqid('phpspreadsheet.', true) . '.'; + return Settings::getCache() instanceof Memory + ? random_bytes(7) . ':' + : uniqid('phpspreadsheet.', true) . '.'; } /**