"Fossies" - the Fresh Open Source Software Archive 
Member "serendipity/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApc.php" (20 Nov 2022, 3569 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 "AdapterApc.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 * AdapterApc: a APC-Cache adapter
9 *
10 * @see http://php.net/manual/de/book.apc.php
11 */
12 class AdapterApc 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('apc_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('apc_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 apc-cache exists.
54 *
55 * WARNING: use $this->exists($key) instead
56 *
57 * @param string $key
58 *
59 * @return bool
60 *
61 * @internal
62 */
63 public function apc_cache_exists($key): bool
64 {
65 return (bool) \apc_fetch($key);
66 }
67
68 /**
69 * Clears the APC cache by type.
70 *
71 * @param string $type - If $type is "user", the user cache will be cleared; otherwise,
72 * the system cache (cached files) will be cleared
73 *
74 * @return bool
75 *
76 * @internal
77 */
78 public function cacheClear(string $type): bool
79 {
80 return (bool) \apc_clear_cache($type);
81 }
82
83 /**
84 * Retrieves cached information from APC's data store
85 *
86 * @param string $type - If $type is "user", information about the user cache will be returned
87 * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache
88 * entries. This is useful when trying to optimize calls for statistics gathering
89 *
90 * @return array
91 * <p>Array of cached data (and meta-data) or empty array on failure.</p>
92 */
93 public function cacheInfo(string $type = '', bool $limited = false): array
94 {
95 /** @var array|false $return */
96 $return = \apc_cache_info($type, $limited);
97
98 if ($return === false) {
99 return [];
100 }
101
102 return $return;
103 }
104
105 /**
106 * {@inheritdoc}
107 */
108 public function exists(string $key): bool
109 {
110 if (\function_exists('apc_exists')) {
111 return (bool) \apc_exists($key);
112 }
113
114 return $this->apc_cache_exists($key);
115 }
116
117 /**
118 * {@inheritdoc}
119 */
120 public function get(string $key)
121 {
122 if ($this->exists($key)) {
123 return \apc_fetch($key);
124 }
125
126 return null;
127 }
128
129 /**
130 * {@inheritdoc}
131 */
132 public function installed(): bool
133 {
134 return $this->installed;
135 }
136
137 /**
138 * {@inheritdoc}
139 */
140 public function remove(string $key): bool
141 {
142 return (bool) \apc_delete($key);
143 }
144
145 /**
146 * {@inheritdoc}
147 */
148 public function removeAll(): bool
149 {
150 return (bool) ($this->cacheClear('system') && $this->cacheClear('user'));
151 }
152
153 /**
154 * {@inheritdoc}
155 */
156 public function set(string $key, $value): bool
157 {
158 return (bool) \apc_store($key, $value);
159 }
160
161 /**
162 * {@inheritdoc}
163 */
164 public function setExpired(string $key, $data, int $ttl = 0): bool
165 {
166 return (bool) \apc_store($key, $data, $ttl);
167 }
168 }