Elgg  Version 3.0
cache.php
Go to the documentation of this file.
1 <?php
16  return _elgg_services()->fileCache;
17 }
18 
25  _elgg_services()->systemCache->reset();
26 }
27 
37  return _elgg_services()->systemCache->save($type, $data);
38 }
39 
48  return _elgg_services()->systemCache->load($type);
49 }
50 
59  return _elgg_services()->systemCache->delete($type);
60 }
61 
69  return _elgg_services()->systemCache->isEnabled();
70 }
71 
81  _elgg_services()->systemCache->enable();
82 }
83 
93  _elgg_services()->systemCache->disable();
94 }
95 
96 /* Simplecache */
97 
113 function elgg_register_simplecache_view($view_name) {
114  _elgg_services()->views->registerCacheableView($view_name);
115 }
116 
141 function elgg_get_simplecache_url($view, $subview = '') {
142  return _elgg_services()->simpleCache->getUrl($view, $subview);
143 }
144 
152  return _elgg_services()->simpleCache->isEnabled();
153 }
154 
163  _elgg_services()->simpleCache->enable();
164 }
165 
176  _elgg_services()->simpleCache->disable();
177 }
178 
190 function _elgg_rmdir($dir, $empty = false) {
191  if (empty($dir)) {
192  // realpath can return false
193  _elgg_services()->logger->warning(__FUNCTION__ . ' called with empty $dir');
194  return true;
195  }
196  if (!is_dir($dir)) {
197  return true;
198  }
199 
200  $files = array_diff(scandir($dir), ['.', '..']);
201 
202  foreach ($files as $file) {
203  if (is_dir("$dir/$file")) {
204  _elgg_rmdir("$dir/$file");
205  } else {
206  unlink("$dir/$file");
207  }
208  }
209 
210  if ($empty) {
211  return true;
212  }
213 
214  return rmdir($dir);
215 }
216 
225  _elgg_services()->simpleCache->invalidate();
226 }
227 
234 function elgg_flush_caches() {
235  // this event sequence could take while, make sure there is no timeout
236  set_time_limit(0);
237 
238  _elgg_services()->events->triggerSequence('cache:flush', 'system');
239 }
240 
248  $root_path = elgg_get_root_path();
249 
250  $simplecache_path = elgg_get_asset_path();
251  $symlink_path = "{$root_path}cache";
252 
253  if (!is_dir($simplecache_path)) {
254  return false;
255  }
256  return is_dir($symlink_path) && realpath($simplecache_path) == realpath($symlink_path);
257 }
258 
266 
267  if (_elgg_is_cache_symlinked()) {
268  // Symlink exists, no need to proceed
269  return true;
270  }
271 
272  $root_path = elgg_get_root_path();
273  $simplecache_path = rtrim(elgg_get_asset_path(), '/');
274  $symlink_path = "{$root_path}cache";
275 
276  if (is_dir($symlink_path)) {
277  // Cache directory already exists
278  // We can not proceed without overwriting files
279  return false;
280  }
281 
282  if (!is_dir($simplecache_path)) {
283  // Views simplecache directory has not yet been created
284  mkdir($simplecache_path, 0755, true);
285  }
286 
287  symlink($simplecache_path, $symlink_path);
288 
289  if (_elgg_is_cache_symlinked()) {
290  return true;
291  }
292 
293  if (is_dir($symlink_path)) {
294  unlink($symlink_path);
295  }
296 
297  return false;
298 }
299 
307 function _elgg_cache_init() {
308  _elgg_services()->systemCache->init();
309 }
310 
318  _elgg_services()->boot->getCache()->disable();
319  _elgg_services()->plugins->getCache()->disable();
320  _elgg_services()->sessionCache->disable();
321  _elgg_services()->dataCache->disable();
322  _elgg_services()->dic_cache->getCache()->disable();
323  _elgg_services()->autoloadManager->getCache()->disable();
324  _elgg_services()->systemCache->getCache()->disable();
325 }
326 
333 function _elgg_clear_caches() {
334  _elgg_services()->boot->invalidateCache();
335  _elgg_services()->plugins->clear();
336  _elgg_services()->sessionCache->clear();
337  _elgg_services()->dataCache->clear();
338  _elgg_services()->dic_cache->flushAll();
339  _elgg_services()->simpleCache->invalidate();
340  _elgg_services()->autoloadManager->deleteCache();
341  _elgg_services()->fileCache->clear();
342 }
343 
351  if (!function_exists('opcache_reset')) {
352  return;
353  }
354 
355  opcache_reset();
356 }
357 
365  _elgg_services()->boot->getCache()->enable();
366  _elgg_services()->plugins->getCache()->enable();
367  _elgg_services()->sessionCache->enable();
368  _elgg_services()->dataCache->enable();
369  _elgg_services()->dic_cache->getCache()->enable();
370  _elgg_services()->autoloadManager->getCache()->enable();
371  _elgg_services()->systemCache->getCache()->enable();
372 }
373 
381  $services = _elgg_services();
382 
383  $dic_builder = new \DI\ContainerBuilder(\Elgg\Di\PublicContainer::class);
384  $dic_builder->useAnnotations(false);
385  $dic_builder->setDefinitionCache($services->dic_cache);
386 
387  $definitions = $services->dic_loader->getDefinitions();
388  foreach ($definitions as $definition) {
389  $dic_builder->addDefinitions($definition);
390  }
391 
392  $dic = $dic_builder->build();
393 
394  _elgg_services()->setValue('dic_builder', $dic_builder);
395  _elgg_services()->setValue('dic', $dic);
396 }
397 
401 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
402  $events->registerHandler('ready', 'system', '_elgg_cache_init');
403 
404  $events->registerHandler('cache:flush:before', 'system', '_elgg_disable_caches');
405  $events->registerHandler('cache:flush', 'system', '_elgg_clear_caches');
406  $events->registerHandler('cache:flush', 'system', '_elgg_reset_opcache');
407  $events->registerHandler('cache:flush:after', 'system', '_elgg_enable_caches');
408  $events->registerHandler('cache:flush:after', 'system', '_elgg_rebuild_public_container');
409 };
elgg_enable_system_cache()
Enables the system disk cache.
Definition: cache.php:80
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
Definition: cache.php:24
_elgg_is_cache_symlinked()
Checks if /cache directory has been symlinked to views simplecache directory.
Definition: cache.php:247
_elgg_cache_init()
Initializes the simplecache lastcache variable and creates system cache files when appropriate...
Definition: cache.php:307
if(!array_key_exists($filename, $text_files)) $file
elgg_get_asset_path()
Get the asset cache directory path for this installation, ending with slash.
elgg_invalidate_simplecache()
Deletes all cached views in the simplecache and sets the lastcache and lastupdate time to 0 for every...
Definition: cache.php:224
_elgg_symlink_cache()
Symlinks /cache directory to views simplecache directory.
Definition: cache.php:265
_elgg_rebuild_public_container()
Rebuild public service container.
Definition: cache.php:380
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:113
_elgg_reset_opcache()
Resets OPcache.
Definition: cache.php:350
elgg_disable_system_cache()
Disables the system disk cache.
Definition: cache.php:92
elgg_get_simplecache_url($view, $subview= '')
Get the URL for the cached view.
Definition: cache.php:141
elgg_get_system_cache()
Returns an object suitable for caching system information.
Definition: cache.php:15
Events service.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
_elgg_disable_caches()
Disable all caches.
Definition: cache.php:317
$type
Definition: delete.php:21
Configuration exception.
if(!$owner||!$owner->canEdit()) if(!$owner->hasIcon('master')) if(!$owner->saveIconFromElggFile($owner->getIcon('master'), 'icon', $coords)) $view
Definition: crop.php:30
Base class for events and hooks.
elgg_get_root_path()
Get the project path (where composer is installed), ending with slash.
_elgg_clear_caches()
Clear all caches.
Definition: cache.php:333
_elgg_rmdir($dir, $empty=false)
Recursively deletes a directory, including all hidden files.
Definition: cache.php:190
elgg_delete_system_cache($type)
Deletes the contents of a system cache.
Definition: cache.php:58
elgg_load_system_cache($type)
Retrieve the contents of a system cache.
Definition: cache.php:47
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:151
elgg_disable_simplecache()
Disables the simple cache.
Definition: cache.php:175
elgg_save_system_cache($type, $data)
Saves a system cache.
Definition: cache.php:36
elgg_is_system_cache_enabled()
Is system cache enabled.
Definition: cache.php:68
class
Definition: placeholder.php:21
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
_elgg_enable_caches()
Enable all caches.
Definition: cache.php:364
elgg_enable_simplecache()
Enables the simple cache.
Definition: cache.php:162
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
Definition: details.php:142
elgg_flush_caches()
Flush all the registered caches.
Definition: cache.php:234