Elgg  Version 3.0
SystemCache.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Cache;
3 
5 use Elgg\Config;
7 use ElggCache;
8 
15 class SystemCache {
16 
17  use Profilable;
18  use Cacheable;
19 
23  private $config;
24 
31  public function __construct(ElggCache $cache, Config $config) {
32  $this->cache = $cache;
33  $this->config = $config;
34  }
35 
41  public function reset() {
42  $this->cache->clear();
43  }
44 
53  public function save($type, $data) {
54  if ($this->isEnabled()) {
55  return $this->cache->save($type, $data);
56  }
57 
58  return false;
59  }
60 
68  public function load($type) {
69  if (!$this->isEnabled()) {
70  return;
71  }
72 
73  $cached_data = $this->cache->load($type);
74  if (isset($cached_data)) {
75  return $cached_data;
76  }
77  }
78 
85  public function delete($type) {
86  return $this->cache->delete($type);
87  }
88 
94  public function isEnabled() {
95  return (bool) $this->config->system_cache_enabled;
96  }
97 
106  public function enable() {
107  $this->config->save('system_cache_enabled', 1);
108  $this->reset();
109  }
110 
119  public function disable() {
120  $this->config->save('system_cache_enabled', 0);
121  $this->reset();
122  }
123 
130  public function init() {
131  if (!$this->isEnabled()) {
132  return;
133  }
134 
135  // cache system data if enabled and not loaded
136  if (!$this->config->system_cache_loaded) {
137  _elgg_services()->views->cacheConfiguration($this);
138  }
139  }
140 }
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:41
isEnabled()
Is system cache enabled.
Definition: SystemCache.php:94
__construct(ElggCache $cache, Config $config)
Constructor.
Definition: SystemCache.php:31
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
$type
Definition: delete.php:21
trait Profilable
Make an object accept a timer.
Definition: Profilable.php:10
enable()
Enables the system disk cache.
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:11
save($type, $data)
Saves a system cache.
Definition: SystemCache.php:53
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
init()
Initializes the simplecache lastcache variable and creates system cache files when appropriate...
disable()
Disables the system disk cache.
load($type)
Retrieve the contents of a system cache.
Definition: SystemCache.php:68