Elgg  Version 6.0
SystemCache.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cache;
4 
5 use Elgg\Config;
7 
14 class SystemCache {
15 
16  use Cacheable;
17 
24  public function __construct(BaseCache $cache, protected Config $config) {
25  $this->cache = $cache;
26  }
27 
33  public function reset() {
34  $this->cache->clear();
35  }
36 
46  public function save(string $type, $data, int $expire_after = null): bool {
47  if ($this->isEnabled()) {
48  return $this->cache->save($type, $data, $expire_after);
49  }
50 
51  return false;
52  }
53 
61  public function load(string $type) {
62  if (!$this->isEnabled()) {
63  return;
64  }
65 
66  $cached_data = $this->cache->load($type);
67  if (isset($cached_data)) {
68  return $cached_data;
69  }
70  }
71 
78  public function delete(string $type) {
79  return $this->cache->delete($type);
80  }
81 
87  public function isEnabled() {
88  return (bool) $this->config->system_cache_enabled;
89  }
90 
99  public function enable() {
100  $this->config->save('system_cache_enabled', 1);
101  $this->reset();
102  }
103 
112  public function disable() {
113  $this->config->save('system_cache_enabled', 0);
114  $this->reset();
115  }
116 }
save(string $type, $data, int $expire_after=null)
Saves a system cache.
Definition: SystemCache.php:46
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:33
isEnabled()
Is system cache enabled.
Definition: SystemCache.php:87
$type
Definition: delete.php:21
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
load(string $type)
Retrieve the contents of a system cache.
Definition: SystemCache.php:61
enable()
Enables the system disk cache.
Definition: SystemCache.php:99
The Elgg cache base class.
Definition: BaseCache.php:9
__construct(BaseCache $cache, protected Config $config)
Constructor.
Definition: SystemCache.php:24
disable()
Disables the system disk cache.
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:13