Skip to content

Commit abcd82f

Browse files
Extract common cache data preparation logic to prepareCacheData method
1 parent 6804fbe commit abcd82f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

framework/caching/Cache.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,7 @@ public function multiSet($items, $duration = null, $dependency = null)
294294
$duration = $this->defaultDuration;
295295
}
296296

297-
if ($dependency !== null && $this->serializer !== false) {
298-
$dependency->evaluateDependency($this);
299-
}
300-
301-
$data = [];
302-
foreach ($items as $key => $value) {
303-
if ($this->serializer === null) {
304-
$value = serialize([$value, $dependency]);
305-
} elseif ($this->serializer !== false) {
306-
$value = call_user_func($this->serializer[0], [$value, $dependency]);
307-
}
308-
309-
$key = $this->buildKey($key);
310-
$data[$key] = $value;
311-
}
297+
$data = $this->prepareCacheData($items, $dependency);
312298

313299
return $this->setValues($data, $duration);
314300
}
@@ -343,6 +329,21 @@ public function madd($items, $duration = 0, $dependency = null)
343329
* @since 2.0.7
344330
*/
345331
public function multiAdd($items, $duration = 0, $dependency = null)
332+
{
333+
$data = $this->prepareCacheData($items, $dependency);
334+
335+
return $this->addValues($data, $duration);
336+
}
337+
338+
/**
339+
* Prepares data for caching by serializing values and evaluating dependencies.
340+
*
341+
* @param array $items The items to be cached.
342+
* @param mixed $dependency The dependency to be evaluated.
343+
*
344+
* @return array The prepared data for caching.
345+
*/
346+
private function prepareCacheData($items, $dependency)
346347
{
347348
if ($dependency !== null && $this->serializer !== false) {
348349
$dependency->evaluateDependency($this);
@@ -360,7 +361,7 @@ public function multiAdd($items, $duration = 0, $dependency = null)
360361
$data[$key] = $value;
361362
}
362363

363-
return $this->addValues($data, $duration);
364+
return $data;
364365
}
365366

366367
/**

0 commit comments

Comments
 (0)