Elgg  Version 4.3
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  private $config;
22 
29  public function __construct(\ElggCache $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($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($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($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 }
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:39
isEnabled()
Is system cache enabled.
Definition: SystemCache.php:93
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
$type
Definition: delete.php:21
__construct(\ElggCache $cache, Config $config)
Constructor.
Definition: SystemCache.php:29
enable()
Enables the system disk cache.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
save($type, $data, int $expire_after=null)
Saves a system cache.
Definition: SystemCache.php:52
init()
Initializes the system cache.
disable()
Disables the system disk cache.
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:13
load($type)
Retrieve the contents of a system cache.
Definition: SystemCache.php:67