Elgg  Version 1.11
SystemCache.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Cache;
3 
13 class SystemCache {
19  private $CONFIG;
20 
24  public function __construct() {
25  global $CONFIG;
26  $this->CONFIG = $CONFIG;
27  }
28 
37  function getFileCache() {
38 
39 
43  static $FILE_PATH_CACHE;
44 
45  if (!$FILE_PATH_CACHE) {
46  $FILE_PATH_CACHE = new \ElggFileCache($this->CONFIG->dataroot . 'system_cache/');
47  }
48 
49  return $FILE_PATH_CACHE;
50  }
51 
57  function reset() {
58  $this->getFileCache()->clear();
59  }
60 
68  function save($type, $data) {
69 
70 
71  if ($this->CONFIG->system_cache_enabled) {
72  return $this->getFileCache()->save($type, $data);
73  }
74 
75  return false;
76  }
77 
84  function load($type) {
85 
86 
87  if ($this->CONFIG->system_cache_enabled) {
88  $cached_data = $this->getFileCache()->load($type);
89 
90  if ($cached_data) {
91  return $cached_data;
92  }
93  }
94 
95  return null;
96  }
97 
106  function enable() {
107 
108 
109  _elgg_services()->datalist->set('system_cache_enabled', 1);
110  $this->CONFIG->system_cache_enabled = 1;
111  $this->reset();
112  }
113 
122  function disable() {
123 
124 
125  _elgg_services()->datalist->set('system_cache_enabled', 0);
126  $this->CONFIG->system_cache_enabled = 0;
127  $this->reset();
128  }
129 
136  function loadAll() {
137 
138 
139  $this->CONFIG->system_cache_loaded = false;
140 
141  $this->CONFIG->views = new \stdClass();
142  $data = $this->load('view_locations');
143  if (!is_string($data)) {
144  return;
145  }
146  $this->CONFIG->views->locations = unserialize($data);
147 
148  $data = $this->load('view_types');
149  if (!is_string($data)) {
150  return;
151  }
152  $this->CONFIG->view_types = unserialize($data);
153 
154  // Note: We don't need view_overrides for operation. Inspector can pull this from the cache
155 
156  $this->CONFIG->system_cache_loaded = true;
157  }
158 
165  function init() {
166  if (!$this->CONFIG->system_cache_enabled) {
167  return;
168  }
169 
170  // cache system data if enabled and not loaded
171  if (!$this->CONFIG->system_cache_loaded) {
172  $this->save('view_locations', serialize($this->CONFIG->views->locations));
173  $this->save('view_types', serialize($this->CONFIG->view_types));
174 
175  // this is saved just for the inspector and is not loaded in loadAll()
176  $this->save('view_overrides', serialize(_elgg_services()->views->getOverriddenLocations()));
177  }
178 
179  if (!$this->CONFIG->i18n_loaded_from_cache) {
180  _elgg_services()->translator->reloadAllTranslations();
181  foreach ($this->CONFIG->translations as $lang => $map) {
182  $this->save("$lang.lang", serialize($map));
183  }
184  }
185  }
186 }
$lang
Definition: html.php:12
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:57
$data
Definition: opendd.php:13
getFileCache()
Returns an object suitable for caching system information.
Definition: SystemCache.php:37
__construct()
Constructor.
Definition: SystemCache.php:24
$CONFIG views
Holds information about views.
Definition: config.php:243
_elgg_services()
Definition: autoloader.php:14
enable()
Enables the system disk cache.
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
loadAll()
Loads the system cache during engine boot.
save($type, $data)
Saves a system cache.
Definition: SystemCache.php:68
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:84