• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / cache / 15647374799

14 Jun 2025 02:07AM UTC coverage: 95.255% (-0.03%) from 95.281%
15647374799

push

github

natanfelles
Remove ApcuCache::setCustomSerializer method

1 of 1 new or added line in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

522 of 548 relevant lines covered (95.26%)

57.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/src/ApcuCache.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Cache Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\Cache;
11

12
use RuntimeException;
13

14
/**
15
 * Class ApcuCache.
16
 *
17
 * @package cache
18
 */
19
class ApcuCache extends Cache
20
{
21
    /**
22
     * APCu Cache handler configurations.
23
     *
24
     * @var array<string,mixed>
25
     */
26
    protected array $configs = [
27
        'use_custom_serializer' => true,
28
    ];
29

30
    protected function initialize() : void
31
    {
32
        if (!\apcu_enabled()) {
108✔
UNCOV
33
            throw new RuntimeException('APCu extension is not enabled');
×
34
        }
35
    }
36

37
    public function isUsingCustomSerializer() : bool
38
    {
39
        return $this->configs['use_custom_serializer'];
66✔
40
    }
41

42
    public function get(string $key) : mixed
43
    {
44
        if (isset($this->debugCollector)) {
66✔
45
            $start = \microtime(true);
12✔
46
            return $this->addDebugGet(
12✔
47
                $key,
12✔
48
                $start,
12✔
49
                $this->getValue($key)
12✔
50
            );
12✔
51
        }
52
        return $this->getValue($key);
54✔
53
    }
54

55
    protected function getValue(string $key) : mixed
56
    {
57
        $key = \apcu_fetch($this->renderKey($key), $success);
66✔
58
        if ($success && $this->isUsingCustomSerializer()) {
66✔
59
            $key = $this->unserialize($key);
45✔
60
        }
61
        return $success
66✔
62
            ? $key
54✔
63
            : null;
66✔
64
    }
65

66
    protected function makeValue(mixed $value) : mixed
67
    {
68
        if ($this->isUsingCustomSerializer()) {
60✔
69
            return $this->serialize($value);
50✔
70
        }
71
        return $value;
10✔
72
    }
73

74
    public function set(string $key, mixed $value, ?int $ttl = null) : bool
75
    {
76
        if (isset($this->debugCollector)) {
60✔
77
            $start = \microtime(true);
6✔
78
            return $this->addDebugSet(
6✔
79
                $key,
6✔
80
                $ttl,
6✔
81
                $start,
6✔
82
                $value,
6✔
83
                \apcu_store(
6✔
84
                    $this->renderKey($key),
6✔
85
                    $this->makeValue($value),
6✔
86
                    $this->makeTtl($ttl)
6✔
87
                )
6✔
88
            );
6✔
89
        }
90
        return \apcu_store(
54✔
91
            $this->renderKey($key),
54✔
92
            $this->makeValue($value),
54✔
93
            $this->makeTtl($ttl)
54✔
94
        );
54✔
95
    }
96

97
    public function delete(string $key) : bool
98
    {
99
        if (isset($this->debugCollector)) {
18✔
100
            $start = \microtime(true);
6✔
101
            return $this->addDebugDelete(
6✔
102
                $key,
6✔
103
                $start,
6✔
104
                \apcu_delete($this->renderKey($key))
6✔
105
            );
6✔
106
        }
107
        return \apcu_delete($this->renderKey($key));
12✔
108
    }
109

110
    public function flush() : bool
111
    {
112
        if (isset($this->debugCollector)) {
108✔
113
            $start = \microtime(true);
24✔
114
            return $this->addDebugFlush(
24✔
115
                $start,
24✔
116
                \apcu_clear_cache()
24✔
117
            );
24✔
118
        }
119
        return \apcu_clear_cache();
84✔
120
    }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc