Memory::__destruct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Memory adaptor
4
 * User: moyo
5
 * Date: 15/11/2017
6
 * Time: 4:56 PM
7
 */
8
9
namespace Carno\Cache\Adaptors;
10
11
use Carno\Cache\Blocks;
12
use Carno\Cache\Chips\Delegate;
13
use Carno\Cache\Chips\Prefixed;
14
use Carno\Cache\Chips\Properties;
15
use Carno\Cache\Chips\Storage;
16
use Carno\Cache\Eviction;
17
use Carno\Cache\Refreshing;
18
use Carno\Cache\Stores\Apcu;
19
use Carno\Cache\Stores\Local;
20
21
abstract class Memory
22
{
23
    use Properties, Prefixed, Storage, Delegate;
24
25
    /**
26
     * Memory constructor.
27
     * @param Refreshing $refresher
28
     * @param Eviction $eviction
29
     */
30
    final public function __construct(Refreshing $refresher, Eviction $eviction)
31
    {
32
        $this->refresher = $refresher;
33
        $this->backend =
34
            (extension_loaded('apcu') && ini_get('apc.enable_cli'))
35
                ? new Apcu
36
                : Blocks::join(new Local($eviction))
37
        ;
38
    }
39
40
    /**
41
     */
42
    final public function __destruct()
43
    {
44
        if ($this->backend instanceof Local) {
45
            Blocks::forget($this->backend);
46
        }
47
    }
48
}
49