Elgg  Version 6.0
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()->simpleCache->registerCacheableView($view_name);
113 }
114 
130 function elgg_get_simplecache_url(string $view): string {
131  return _elgg_services()->simpleCache->getUrl($view);
132 }
133 
140 function elgg_is_simplecache_enabled(): bool {
141  return _elgg_services()->simpleCache->isEnabled();
142 }
143 
152  _elgg_services()->simpleCache->enable();
153 }
154 
165  _elgg_services()->simpleCache->disable();
166 }
167 
175  // this event sequence could take while, make sure there is no timeout
176  set_time_limit(0);
177 
178  _elgg_services()->config->save('lastcache', time());
179 
180  _elgg_services()->events->triggerSequence('cache:invalidate', 'system');
181 }
182 
189 function elgg_clear_caches(): void {
190  // this event sequence could take while, make sure there is no timeout
191  set_time_limit(0);
192 
193  _elgg_services()->events->triggerSequence('cache:clear', 'system');
194 }
195 
204 function elgg_purge_caches(): void {
205  // this event sequence could take while, make sure there is no timeout
206  set_time_limit(0);
207 
208  _elgg_services()->events->triggerSequence('cache:purge', 'system');
209 }
210 
217 function _elgg_is_cache_symlinked(): bool {
218  $simplecache_path = elgg_get_asset_path();
219  if (!is_dir($simplecache_path)) {
220  return false;
221  }
222 
223  $root_path = elgg_get_root_path();
224  $symlink_path = "{$root_path}cache";
225 
226  return is_dir($symlink_path) && realpath($simplecache_path) === realpath($symlink_path);
227 }
228 
235 function _elgg_symlink_cache(): bool {
236 
237  if (_elgg_is_cache_symlinked()) {
238  // Symlink exists, no need to proceed
239  return true;
240  }
241 
242  $root_path = elgg_get_root_path();
243  $simplecache_path = rtrim(elgg_get_asset_path(), '/');
244  $symlink_path = "{$root_path}cache";
245 
246  if (is_dir($symlink_path)) {
247  // Cache directory already exists
248  // We can not proceed without overwriting files
249  return false;
250  }
251 
252  if (!is_dir($simplecache_path)) {
253  // Views simplecache directory has not yet been created
254  mkdir($simplecache_path, 0755, true);
255  }
256 
257  symlink($simplecache_path, $symlink_path);
258 
259  if (_elgg_is_cache_symlinked()) {
260  return true;
261  }
262 
263  if (is_dir($symlink_path)) {
264  unlink($symlink_path);
265  }
266 
267  return false;
268 }
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:217
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:235
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:21
elgg_invalidate_caches()
Invalidate all the registered caches.
Definition: cache.php:174
elgg_purge_caches()
Purge all the registered caches.
Definition: cache.php:204
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:140
elgg_disable_simplecache()
Disables the simple cache.
Definition: cache.php:164
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:351
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:151
elgg_get_simplecache_url(string $view)
Get the URL for the cached view.
Definition: cache.php:130
elgg_clear_caches()
Clear all the registered caches.
Definition: cache.php:189