Elgg  Version 1.10
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 get() {
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  $cache = elgg_get_system_cache();
59  $cache->clear();
60  }
61 
69  function save($type, $data) {
70 
71 
72  if ($this->CONFIG->system_cache_enabled) {
73  $cache = elgg_get_system_cache();
74  return $cache->save($type, $data);
75  }
76 
77  return false;
78  }
79 
86  function load($type) {
87 
88 
89  if ($this->CONFIG->system_cache_enabled) {
90  $cache = elgg_get_system_cache();
91  $cached_data = $cache->load($type);
92 
93  if ($cached_data) {
94  return $cached_data;
95  }
96  }
97 
98  return null;
99  }
100 
109  function enable() {
110 
111 
112  _elgg_services()->datalist->set('system_cache_enabled', 1);
113  $this->CONFIG->system_cache_enabled = 1;
115  }
116 
125  function disable() {
126 
127 
128  _elgg_services()->datalist->set('system_cache_enabled', 0);
129  $this->CONFIG->system_cache_enabled = 0;
131  }
132 
139  function loadAll() {
140 
141 
142  $this->CONFIG->system_cache_loaded = false;
143 
144  $this->CONFIG->views = new \stdClass();
145  $data = elgg_load_system_cache('view_locations');
146  if (!is_string($data)) {
147  return;
148  }
149  $this->CONFIG->views->locations = unserialize($data);
150 
151  $data = elgg_load_system_cache('view_types');
152  if (!is_string($data)) {
153  return;
154  }
155  $this->CONFIG->view_types = unserialize($data);
156 
157  $this->CONFIG->system_cache_loaded = true;
158  }
159 
166  function init() {
167  // cache system data if enabled and not loaded
168  if ($this->CONFIG->system_cache_enabled && !$this->CONFIG->system_cache_loaded) {
169  elgg_save_system_cache('view_locations', serialize($this->CONFIG->views->locations));
170  elgg_save_system_cache('view_types', serialize($this->CONFIG->view_types));
171  }
172 
173  if ($this->CONFIG->system_cache_enabled && !$this->CONFIG->i18n_loaded_from_cache) {
174  _elgg_services()->translator->reloadAllTranslations();
175  foreach ($this->CONFIG->translations as $lang => $map) {
176  elgg_save_system_cache("$lang.lang", serialize($map));
177  }
178  }
179  }
180 }
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
Definition: cache.php:29
$lang
Definition: html.php:12
reset()
Reset the system cache by deleting the caches.
Definition: SystemCache.php:57
elgg_get_system_cache()
Returns an object suitable for caching system information.
Definition: cache.php:20
$data
Definition: opendd.php:13
if(!$autoload_available) _elgg_services()
Definition: autoloader.php:20
__construct()
Constructor.
Definition: SystemCache.php:24
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:69
elgg_load_system_cache($type)
Retrieve the contents of a system cache.
Definition: cache.php:50
elgg_save_system_cache($type, $data)
Saves a system cache.
Definition: cache.php:40
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:86