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

aplus-framework / cache / 16306742406

15 Jul 2025 11:44PM UTC coverage: 95.194%. Remained the same
16306742406

push

github

natanfelles
Add since tag

515 of 541 relevant lines covered (95.19%)

55.5 hits per line

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

97.87
/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
 * @since 4.3
20
 */
21
class ApcuCache extends Cache
22
{
23
    protected function initialize() : void
24
    {
25
        if (!\apcu_enabled()) {
85✔
26
            throw new RuntimeException('APCu extension is not enabled');
×
27
        }
28
    }
29

30
    public function get(string $key) : mixed
31
    {
32
        if (isset($this->debugCollector)) {
55✔
33
            $start = \microtime(true);
10✔
34
            return $this->addDebugGet(
10✔
35
                $key,
10✔
36
                $start,
10✔
37
                $this->getValue($key)
10✔
38
            );
10✔
39
        }
40
        return $this->getValue($key);
45✔
41
    }
42

43
    protected function getValue(string $key) : mixed
44
    {
45
        $key = \apcu_fetch($this->renderKey($key), $success);
55✔
46
        return $success
55✔
47
            ? $this->unserialize($key)
45✔
48
            : null;
55✔
49
    }
50

51
    public function set(string $key, mixed $value, ?int $ttl = null) : bool
52
    {
53
        if (isset($this->debugCollector)) {
50✔
54
            $start = \microtime(true);
5✔
55
            return $this->addDebugSet(
5✔
56
                $key,
5✔
57
                $ttl,
5✔
58
                $start,
5✔
59
                $value,
5✔
60
                \apcu_store(
5✔
61
                    $this->renderKey($key),
5✔
62
                    $this->serialize($value),
5✔
63
                    $this->makeTtl($ttl)
5✔
64
                )
5✔
65
            );
5✔
66
        }
67
        return \apcu_store(
45✔
68
            $this->renderKey($key),
45✔
69
            $this->serialize($value),
45✔
70
            $this->makeTtl($ttl)
45✔
71
        );
45✔
72
    }
73

74
    public function delete(string $key) : bool
75
    {
76
        if (isset($this->debugCollector)) {
15✔
77
            $start = \microtime(true);
5✔
78
            return $this->addDebugDelete(
5✔
79
                $key,
5✔
80
                $start,
5✔
81
                \apcu_delete($this->renderKey($key))
5✔
82
            );
5✔
83
        }
84
        return \apcu_delete($this->renderKey($key));
10✔
85
    }
86

87
    public function flush() : bool
88
    {
89
        if (isset($this->debugCollector)) {
85✔
90
            $start = \microtime(true);
20✔
91
            return $this->addDebugFlush(
20✔
92
                $start,
20✔
93
                \apcu_clear_cache()
20✔
94
            );
20✔
95
        }
96
        return \apcu_clear_cache();
65✔
97
    }
98
}
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