Elgg  Version 5.1
cache.php
Go to the documentation of this file.
1 <?php
12 function elgg_get_system_cache(): \Elgg\Cache\BaseCache {
13  return _elgg_services()->fileCache;
14 }
15 
22  _elgg_services()->systemCache->reset();
23 }
24 
34 function elgg_save_system_cache(string $type, $data, int $expire_after = null): bool {
35  return _elgg_services()->systemCache->save($type, $data, $expire_after);
36 }
37 
45 function elgg_load_system_cache(string $type) {
46  return _elgg_services()->systemCache->load($type);
47 }
48 
56 function elgg_delete_system_cache(string $type): bool {
57  return _elgg_services()->systemCache->delete($type);
58 }
59 
66 function elgg_is_system_cache_enabled(): bool {
67  return _elgg_services()->systemCache->isEnabled();
68 }
69 
79  _elgg_services()->systemCache->enable();
80 }
81 
91  _elgg_services()->systemCache->disable();
92 }
93 
94 /* Simplecache */
95 
111 function elgg_register_simplecache_view(string $view_name): void {
112  _elgg_services()->views->registerCacheableView($view_name);
113 }
114 
139 function elgg_get_simplecache_url(string $view, string $subview = ''): string {
140  return _elgg_services()->simpleCache->getUrl($view, $subview);
141 }
142 
149 function elgg_is_simplecache_enabled(): bool {
150  return _elgg_services()->simpleCache->isEnabled();
151 }
152 
161  _elgg_services()->simpleCache->enable();
162 }
163 
174  _elgg_services()->simpleCache->disable();
175 }
176 
184  // this event sequence could take while, make sure there is no timeout
185  set_time_limit(0);
186 
187  _elgg_services()->config->save('lastcache', time());
188 
189  _elgg_services()->events->triggerSequence('cache:invalidate', 'system');
190 }
191 
198 function elgg_clear_caches(): void {
199  // this event sequence could take while, make sure there is no timeout
200  set_time_limit(0);
201 
202  _elgg_services()->events->triggerSequence('cache:clear', 'system');
203 }
204 
213 function elgg_purge_caches(): void {
214  // this event sequence could take while, make sure there is no timeout
215  set_time_limit(0);
216 
217  _elgg_services()->events->triggerSequence('cache:purge', 'system');
218 }
219 
226 function _elgg_is_cache_symlinked(): bool {
227  $simplecache_path = elgg_get_asset_path();
228  if (!is_dir($simplecache_path)) {
229  return false;
230  }
231 
232  $root_path = elgg_get_root_path();
233  $symlink_path = "{$root_path}cache";
234 
235  return is_dir($symlink_path) && realpath($simplecache_path) === realpath($symlink_path);
236 }
237 
244 function _elgg_symlink_cache(): bool {
245 
246  if (_elgg_is_cache_symlinked()) {
247  // Symlink exists, no need to proceed
248  return true;
249  }
250 
251  $root_path = elgg_get_root_path();
252  $simplecache_path = rtrim(elgg_get_asset_path(), '/');
253  $symlink_path = "{$root_path}cache";
254 
255  if (is_dir($symlink_path)) {
256  // Cache directory already exists
257  // We can not proceed without overwriting files
258  return false;
259  }
260 
261  if (!is_dir($simplecache_path)) {
262  // Views simplecache directory has not yet been created
263  mkdir($simplecache_path, 0755, true);
264  }
265 
266  symlink($simplecache_path, $symlink_path);
267 
268  if (_elgg_is_cache_symlinked()) {
269  return true;
270  }
271 
272  if (is_dir($symlink_path)) {
273  unlink($symlink_path);
274  }
275 
276  return false;
277 }
elgg_enable_system_cache()
Enables the system disk cache.
Definition: cache.php:78
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
Definition: cache.php:21
_elgg_is_cache_symlinked()
Checks if /cache directory has been symlinked to views simplecache directory.
Definition: cache.php:226
elgg_get_asset_path()
Get the asset cache directory path for this installation, ending with slash.
_elgg_symlink_cache()
Symlinks /cache directory to views simplecache directory.
Definition: cache.php:244
elgg_disable_system_cache()
Disables the system disk cache.
Definition: cache.php:90
elgg_get_system_cache()
Elgg cache Cache file interface for caching data.
Definition: cache.php:12
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$type
Definition: delete.php:22
elgg_invalidate_caches()
Invalidate all the registered caches.
Definition: cache.php:183
elgg_purge_caches()
Purge all the registered caches.
Definition: cache.php:213
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
elgg_delete_system_cache(string $type)
Deletes the contents of a system cache.
Definition: cache.php:56
elgg_get_root_path()
Get the project path (where composer is installed), ending with slash.
elgg_save_system_cache(string $type, $data, int $expire_after=null)
Saves a system cache.
Definition: cache.php:34
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:149
elgg_disable_simplecache()
Disables the simple cache.
Definition: cache.php:173
elgg_is_system_cache_enabled()
Is system cache enabled.
Definition: cache.php:66
elgg_load_system_cache(string $type)
Retrieve the contents of a system cache.
Definition: cache.php:45
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
elgg_register_simplecache_view(string $view_name)
Registers a view to simple cache.
Definition: cache.php:111
elgg_enable_simplecache()
Enables the simple cache.
Definition: cache.php:160
elgg_get_simplecache_url(string $view, string $subview= '')
Get the URL for the cached view.
Definition: cache.php:139
elgg_clear_caches()
Clear all the registered caches.
Definition: cache.php:198