ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
APCu.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Cache\Adaptor;
22 
26 class APCu extends BaseAdaptor implements Adaptor
27 {
28  protected static ?bool $is_available = null;
29 
30  public function isAvailable(): bool
31  {
32  return self::$is_available ?? self::$is_available = (\function_exists('apcu_fetch') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL));
33  }
34 
35  public function has(string $container, string $key): bool
36  {
37  return apcu_exists($this->buildKey($container, $key));
38  }
39 
40  public function get(string $container, string $key): ?string
41  {
42  $success = false;
43  $return = apcu_fetch($this->buildKey($container, $key), $success) ?: null;
44  if (!$success) {
45  return null;
46  }
47 
48  return $return;
49  }
50 
51  public function set(string $container, string $key, string $value, int $ttl): void
52  {
53  if (!apcu_store($this->buildKey($container, $key), $value, $ttl)) {
54  file_put_contents($container . '_chache.log', $key);
55  }
56  }
57 
58  public function delete(string $container, string $key): void
59  {
60  apcu_delete($this->buildKey($container, $key));
61  }
62 
63  public function flushContainer(string $container): void
64  {
65  apcu_delete(new \APCUIterator('/^' . $this->buildContainerPrefix($container) . '/'));
66  }
67 
68  public function flush(): void
69  {
70  apcu_clear_cache();
71  }
72 }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
buildContainerPrefix(string $container)
Definition: BaseAdaptor.php:47
$container
Definition: wac.php:36
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static bool $is_available
Definition: APCu.php:28
has(string $container, string $key)
Definition: APCu.php:35
flushContainer(string $container)
Definition: APCu.php:63