Elgg  Version 5.1
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 
21  protected $config;
22 
29  public function __construct(BaseCache $cache, Config $config) {
30  $this->cache = $cache;
31  $this->config = $config;
32  }
33 
39  public function reset() {
40  $this->cache->clear();
41  }
42 
52  public function save(string $type, $data, int $expire_after = null): bool {
53  if ($this->isEnabled()) {
54  return $this->cache->save($type, $data, $expire_after);
55  }
56 
57  return false;
58  }
59 
67  public function load(string $type) {
68  if (!$this->isEnabled()) {
69  return;
70  }
71 
72  $cached_data = $this->cache->load($type);
73  if (isset($cached_data)) {
74  return $cached_data;
75  }
76  }
77 
84  public function delete(string $type) {
85  return $this->cache->delete($type);
86  }
87 
93  public function isEnabled() {
94  return (bool) $this->config->system_cache_enabled;
95  }
96 
105  public function enable() {
106  $this->config->save('system_cache_enabled', 1);
107  $this->reset();
108  }
109 
118  public function disable() {
119  $this->config->save('system_cache_enabled', 0);
120  $this->reset();
121  }
122 
128  public function init() {
129  if (!$this->isEnabled()) {
130  return;
131  }
132 
133  // cache system data if enabled and not loaded
134  if (!$this->config->system_cache_loaded) {
135  _elgg_services()->views->cacheConfiguration(_elgg_services()->serverCache);
136  }
137  }
138 }
save(string $type, $data, int $expire_after=null)
Saves a system cache.
Definition: SystemCache.php:52
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:39
isEnabled()
Is system cache enabled.
Definition: SystemCache.php:93
__construct(BaseCache $cache, Config $config)
Constructor.
Definition: SystemCache.php:29
$type
Definition: delete.php:22
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
load(string $type)
Retrieve the contents of a system cache.
Definition: SystemCache.php:67
enable()
Enables the system disk cache.
The Elgg cache base class.
Definition: BaseCache.php:9
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
init()
Initializes the system cache.
disable()
Disables the system disk cache.
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:13