FileCacheBatchProcessor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\CacheStore\Support;
4
5
use Silviooosilva\CacheerPhp\CacheStore\FileCacheStore;
6
use Silviooosilva\CacheerPhp\Exceptions\CacheFileException;
7
use Silviooosilva\CacheerPhp\Helpers\CacheFileHelper;
8
9
/**
10
 * Class FileCacheBatchProcessor
11
 * @author Sílvio Silva <https://github.com/silviooosilva>
12
 * @package Silviooosilva\CacheerPhp
13
 */
14
class FileCacheBatchProcessor
15
{
16
17
    /**
18
     * FileCacheBatchProcessor constructor.
19
     *
20
     * @param FileCacheStore $store
21
     */
22
    public function __construct(private FileCacheStore $store)
23
    {
24
    }
25
26
    /**
27
     * Processes a batch of cache items and stores them.
28
     *
29
     * @param array $batchItems
30
     * @param string $namespace
31
     * @return void
32
     * @throws CacheFileException
33
     */
34
    public function process(array $batchItems, string $namespace): void
35
    {
36
        foreach ($batchItems as $item) {
37
            CacheFileHelper::validateCacheItem($item);
38
            $cacheKey = $item['cacheKey'];
39
            $cacheData = $item['cacheData'];
40
            $mergedData = CacheFileHelper::mergeCacheData($cacheData);
41
            $this->store->putCache($cacheKey, $mergedData, $namespace);
42
        }
43
    }
44
}
45