Completed
Branch feature/pre-split (60f5c0)
by Anton
03:19
created

XCacheStore   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 81
c 0
b 0
f 0
rs 10
wmc 9
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isAvailable() 0 4 1
A has() 0 4 1
A get() 0 4 1
A set() 0 4 1
A delete() 0 4 1
A inc() 0 4 1
A dec() 0 4 1
A clear() 0 4 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Cache\Stores;
10
11
use Spiral\Cache\Prototypes\CacheStore;
12
13
/**
14
 * Talks to xcache functions.
15
 */
16
class XCacheStore extends CacheStore
17
{
18
    /**
19
     * @var string
20
     */
21
    private $prefix;
22
23
    /**
24
     * @param string $prefix
25
     */
26
    public function __construct(string $prefix = 'spiral:')
27
    {
28
        $this->prefix = $prefix;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function isAvailable(): bool
35
    {
36
        return extension_loaded('xcache');
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function has(string $name): bool
43
    {
44
        return xcache_isset($this->prefix . $name);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function get(string $name)
51
    {
52
        return xcache_get($this->prefix . $name);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function set(string $name, $data, $ttl = null)
59
    {
60
        return xcache_set($this->prefix . $name, $data, $this->lifetime($ttl, 0));
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function delete(string $name)
67
    {
68
        xcache_unset($this->prefix . $name);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function inc(string $name, int $delta = 1): int
75
    {
76
        return xcache_inc($this->prefix . $name, $delta);
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function dec(string $name, int $delta = 1): int
83
    {
84
        return xcache_dec($this->prefix . $name, $delta);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     *
90
     * @throws \ErrorException
91
     */
92
    public function clear()
93
    {
94
        xcache_clear_cache(XC_TYPE_VAR);
95
    }
96
}
97