Completed
Push — master ( ea3a48...b57255 )
by Lars
02:48
created

AdapterXcache::removeAll()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
1
<?php
2
3
namespace voku\cache;
4
5
/**
6
 * AdapterXcache: Xcache-adapter
7
 *
8
 * @package   voku\cache
9
 */
10
class AdapterXcache implements iAdapter
11
{
12
  public $installed = false;
13
14
  /**
15
   * __construct
16
   */
17
  public function __construct()
18
  {
19
    if (extension_loaded('xcache') === true) {
20
      $this->installed = true;
21
    }
22
  }
23
24
  /**
25
   * get cached-item by key
26
   *
27
   * @param String $key
28
   *
29
   * @return mixed
30
   */
31
  public function get($key)
32
  {
33
    return xcache_get($key);
34
  }
35
36
  /**
37
   * set cache-item ky key => value
38
   *
39
   * @param string $key
40
   * @param mixed $value
41
   *
42
   * @return bool
43
   */
44
  public function set($key, $value)
45
  {
46
    return xcache_set($key, $value);
47
  }
48
49
  /**
50
   * set expired
51
   *
52
   * @param $key
53
   * @param $value
54
   * @param $ttl
55
   *
56
   * @return bool
57
   */
58
  public function setExpired($key, $value, $ttl)
59
  {
60
    return xcache_set($key, $value, $ttl);
61
  }
62
63
  /**
64
   * remove one cache-item
65
   *
66
   * @param $key
67
   *
68
   * @return bool
69
   */
70
  public function remove($key)
71
  {
72
    return xcache_unset($key);
73
  }
74
75
  /**
76
   * remove all cache-items
77
   *
78
   * @return bool
79
   */
80
  public function removeAll()
81
  {
82
    if (defined('XC_TYPE_VAR')) {
83
      $xCacheCount = xcache_count(XC_TYPE_VAR);
84
      for ($i = 0; $i < $xCacheCount; $i++) {
85
        xcache_clear_cache(XC_TYPE_VAR, $i);
86
      }
87
88
      return true;
89
    }
90
91
    return false;
92
  }
93
94
  /**
95
   * exists
96
   *
97
   * @param $key
98
   *
99
   * @return bool
100
   */
101
  public function exists($key)
102
  {
103
    return xcache_isset($key);
104
  }
105
106
  /**
107
   * check if cache is installed
108
   *
109
   * @return boolean
110
   */
111
  public function installed()
112
  {
113
    return $this->installed;
114
  }
115
116
}
117