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

aplus-framework / cache / 15645326692

13 Jun 2025 10:44PM UTC coverage: 95.094% (-0.2%) from 95.265%
15645326692

push

github

natanfelles
Check if APCu extension is enabled

1 of 2 new or added lines in 1 file covered. (50.0%)

504 of 530 relevant lines covered (95.09%)

54.55 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
class ApcuCache extends Cache
20
{
21
    protected function initialize() : void
22
    {
23
        if (!\apcu_enabled()) {
80✔
NEW
24
            throw new RuntimeException('APCu extension is not enabled');
×
25
        }
26
    }
27

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

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

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

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

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