APCDriver::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Millennium\Cache\Drivers;
4
5
use Millennium\Cache\Interfaces\CacheDriverInterface;
6
7
class APCDriver implements CacheDriverInterface
8
{
9
    private $isAPCu;
10
11
    public function __construct()
12
    {
13
        if (!function_exists('apc_exists') && !function_exists('apcu_exists')) {
14
            throw new \Millennium\Cache\Exceptions\DriverNotFoundException('APC(u) not installed on your system');
15
        }
16
        $this->isAPCu = (bool) function_exists('apcu_exists');
17
    }
18
19
    public function fetch($key)
20
    {
21
        return $this->isAPCu ? apcu_fetch($key) : apc_fetch($key);
22
    }
23
24
    public function remove($key)
25
    {
26
        return $this->isAPCu ? apcu_delete($key) : apc_delete($key);
27
    }
28
29
    public function store($key, $data, $expire = 0)
30
    {
31
        return $this->isAPCu ? apcu_store($key, $data, $expire) : apc_store($key, $data, $expire);
32
    }
33
}
34