Elgg  Version 6.2
BaseCache.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cache;
4 
9 abstract class BaseCache implements \ArrayAccess {
10 
16  private array $variables = [];
17 
18  protected bool $disabled = false;
19 
28  public function setVariable(string $variable, $value): void {
29  $this->variables[$variable] = $value;
30  }
31 
39  public function getVariable(string $variable) {
40  return $this->variables[$variable] ?? null;
41  }
42 
50  public function __get(string $key) {
51  return $this->load($key);
52  }
53 
62  public function __set(string $key, $value): void {
63  $this->save($key, $value);
64  }
65 
73  public function __isset(string $key): bool {
74  return (bool) $this->load($key);
75  }
76 
84  public function __unset(string $key): void {
85  $this->delete($key);
86  }
87 
97  abstract public function save($key, $data, $expire_after = null);
98 
106  abstract public function load($key);
107 
115  abstract public function delete($key);
116 
122  abstract public function clear();
123 
129  abstract public function invalidate();
130 
136  abstract public function purge();
137 
143  public function disable(): void {
144  $this->disabled = true;
145  }
146 
151  public function enable(): void {
152  $this->disabled = false;
153  }
154 
163  public function populate(array $values, ?int $expires_after = null): void {
164  $this->clear();
165  foreach ($values as $key => $value) {
166  $this->save($key, $value, $expires_after);
167  }
168  }
169 
180  public function add(string $key, $data): bool {
181  if (!isset($this[$key])) {
182  return $this->save($key, $data);
183  }
184 
185  return false;
186  }
187 
188  // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
189 
200  #[\ReturnTypeWillChange]
201  public function offsetSet($offset, $value) {
202  $this->save($offset, $value);
203  }
204 
214  #[\ReturnTypeWillChange]
215  public function offsetGet($offset) {
216  return $this->load($offset);
217  }
218 
228  #[\ReturnTypeWillChange]
229  public function offsetUnset($offset) {
230  if (isset($this->$offset)) {
231  unset($this->$offset);
232  }
233  }
234 
244  #[\ReturnTypeWillChange]
245  public function offsetExists($offset) {
246  return isset($this->$offset);
247  }
248 }
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
if(! $entity instanceof \ElggUser) $data
Definition: attributes.php:13
The Elgg cache base class.
Definition: BaseCache.php:9
__isset(string $key)
Supporting isset, using $this->load() with default values.
Definition: BaseCache.php:73
offsetExists($offset)
Does key exist.
Definition: BaseCache.php:245
save($key, $data, $expire_after=null)
Save data in a cache.
enable()
Enable disabled cache.
Definition: BaseCache.php:151
getVariable(string $variable)
Get variables for this cache.
Definition: BaseCache.php:39
add(string $key, $data)
Add a key only if it doesn't already exist.
Definition: BaseCache.php:180
offsetSet($offset, $value)
Assigns a value for the specified key.
Definition: BaseCache.php:201
populate(array $values, ?int $expires_after=null)
Populate cache from an array of key => values.
Definition: BaseCache.php:163
invalidate()
Invalidate the contents of the cache.
clear()
Clear out all the contents of the cache.
disable()
Disable cache Do not write or read from cache.
Definition: BaseCache.php:143
__unset(string $key)
Supporting unsetting of magic attributes.
Definition: BaseCache.php:84
setVariable(string $variable, $value)
Set a cache variable.
Definition: BaseCache.php:28
__get(string $key)
Class member get overloading, returning key using $this->load defaults.
Definition: BaseCache.php:50
offsetUnset($offset)
Unsets a key.
Definition: BaseCache.php:229
offsetGet($offset)
Get the value for specified key.
Definition: BaseCache.php:215
load($key)
Load data from the cache using a given key.
__set(string $key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: BaseCache.php:62
purge()
Purge old/stale contents of the cache.
$value
Definition: generic.php:51
if(empty($count)) $offset
Definition: pagination.php:26
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10