"Fossies" - the Fresh Open Source Software Archive 
Member "serendipity/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApcu.php" (20 Nov 2022, 3308 Bytes) of package /linux/www/serendipity-2.4.0.zip:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "AdapterApcu.php" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.3.5_vs_2.4.0.
1 <?php
2
3 declare(strict_types=1);
4
5 namespace voku\cache;
6
7 /**
8 * AdapterApcu: a APCu-Cache adapter
9 *
10 * @see http://php.net/manual/de/book.apcu.php
11 */
12 class AdapterApcu implements iAdapter
13 {
14 /**
15 * @var bool
16 */
17 public $installed = false;
18
19 /**
20 * @var bool
21 */
22 public $debug = false;
23
24 /**
25 * __construct()
26 */
27 public function __construct()
28 {
29 if (
30 \PHP_SAPI !== 'cli'
31 &&
32 \function_exists('apcu_store') === true
33 &&
34 \ini_get('apc.enabled')
35 ) {
36 $this->installed = true;
37 }
38
39 if (
40 \PHP_SAPI === 'cli'
41 &&
42 \function_exists('apcu_store') === true
43 &&
44 \ini_get('apc.enable_cli')
45 ) {
46 \ini_set('apc.use_request_time', '0');
47
48 $this->installed = true;
49 }
50 }
51
52 /**
53 * Check if apcu-cache exists.
54 *
55 * WARNING: we only keep this method for compatibly-reasons
56 * -> use ->exists($key)
57 *
58 * @param string $key
59 *
60 * @return bool
61 *
62 * @deprecated
63 */
64 public function apcu_cache_exists($key): bool
65 {
66 return $this->exists($key);
67 }
68
69 /**
70 * Clears the APCu cache by type.
71 *
72 * @param string $type <p>WARNING: is not used in APCu only valid for APC</p>
73 *
74 * @return bool
75 *
76 * @internal
77 */
78 public function cacheClear(string $type): bool
79 {
80 return (bool) \apcu_clear_cache();
81 }
82
83 /**
84 * Retrieves cached information from APCu's data store
85 *
86 * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache
87 * entries. This is useful when trying to optimize calls for statistics gathering
88 *
89 * @return array
90 * <p>Array of cached data (and meta-data) or empty array on failure.</p>
91 */
92 public function cacheInfo(bool $limited = false): array
93 {
94 /** @var array|false $return */
95 $return = \apcu_cache_info($limited);
96
97 if ($return === false) {
98 return [];
99 }
100
101 return $return;
102 }
103
104 /**
105 * {@inheritdoc}
106 */
107 public function exists(string $key): bool
108 {
109 return (bool) \apcu_exists($key);
110 }
111
112 /**
113 * {@inheritdoc}
114 */
115 public function get(string $key)
116 {
117 if ($this->exists($key)) {
118 return \apcu_fetch($key);
119 }
120
121 return null;
122 }
123
124 /**
125 * {@inheritdoc}
126 */
127 public function installed(): bool
128 {
129 return $this->installed;
130 }
131
132 /**
133 * {@inheritdoc}
134 */
135 public function remove(string $key): bool
136 {
137 return (bool) \apcu_delete($key);
138 }
139
140 /**
141 * {@inheritdoc}
142 */
143 public function removeAll(): bool
144 {
145 return (bool) ($this->cacheClear('system') && $this->cacheClear('user'));
146 }
147
148 /**
149 * {@inheritdoc}
150 */
151 public function set(string $key, $value): bool
152 {
153 return (bool) \apcu_store($key, $value);
154 }
155
156 /**
157 * {@inheritdoc}
158 */
159 public function setExpired(string $key, $data, int $ttl = 0): bool
160 {
161 return (bool) \apcu_store($key, $data, $ttl);
162 }
163 }