From abcd82fd1765a77e1d87f80a7338c3b428dc18d1 Mon Sep 17 00:00:00 2001 From: salehhashemi1992 <81674631+salehhashemi1992@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:40:26 +0330 Subject: [PATCH] Extract common cache data preparation logic to prepareCacheData method --- framework/caching/Cache.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/framework/caching/Cache.php b/framework/caching/Cache.php index 5e1828ef850..d6d363c6d34 100644 --- a/framework/caching/Cache.php +++ b/framework/caching/Cache.php @@ -294,21 +294,7 @@ public function multiSet($items, $duration = null, $dependency = null) $duration = $this->defaultDuration; } - if ($dependency !== null && $this->serializer !== false) { - $dependency->evaluateDependency($this); - } - - $data = []; - foreach ($items as $key => $value) { - if ($this->serializer === null) { - $value = serialize([$value, $dependency]); - } elseif ($this->serializer !== false) { - $value = call_user_func($this->serializer[0], [$value, $dependency]); - } - - $key = $this->buildKey($key); - $data[$key] = $value; - } + $data = $this->prepareCacheData($items, $dependency); return $this->setValues($data, $duration); } @@ -343,6 +329,21 @@ public function madd($items, $duration = 0, $dependency = null) * @since 2.0.7 */ public function multiAdd($items, $duration = 0, $dependency = null) + { + $data = $this->prepareCacheData($items, $dependency); + + return $this->addValues($data, $duration); + } + + /** + * Prepares data for caching by serializing values and evaluating dependencies. + * + * @param array $items The items to be cached. + * @param mixed $dependency The dependency to be evaluated. + * + * @return array The prepared data for caching. + */ + private function prepareCacheData($items, $dependency) { if ($dependency !== null && $this->serializer !== false) { $dependency->evaluateDependency($this); @@ -360,7 +361,7 @@ public function multiAdd($items, $duration = 0, $dependency = null) $data[$key] = $value; } - return $this->addValues($data, $duration); + return $data; } /**