Elgg  Version 4.x
ElggCache.php
Go to the documentation of this file.
1 <?php
6 abstract class ElggCache implements \ArrayAccess {
12  private $variables = [];
13 
17  protected $disabled = false;
18 
22  public function __construct() {
23  }
24 
33  public function setVariable(string $variable, $value): void {
34  $this->variables[$variable] = $value;
35  }
36 
44  public function getVariable(string $variable) {
45  return $this->variables[$variable] ?? null;
46  }
47 
55  public function __get(string $key) {
56  return $this->load($key);
57  }
58 
67  public function __set(string $key, $value): void {
68  $this->save($key, $value);
69  }
70 
78  public function __isset(string $key): bool {
79  return (bool) $this->load($key);
80  }
81 
89  public function __unset(string $key): void {
90  $this->delete($key);
91  }
92 
102  abstract public function save($key, $data, $expire_after = null);
103 
111  abstract public function load($key);
112 
120  abstract public function delete($key);
121 
127  abstract public function clear();
128 
134  abstract public function invalidate();
135 
141  abstract public function purge();
142 
148  public function disable(): void {
149  $this->disabled = true;
150  }
151 
156  public function enable(): void {
157  $this->disabled = false;
158  }
159 
168  public function populate(array $values, int $expires_after = null): void {
169  $this->clear();
170  foreach ($values as $key => $value) {
171  $this->save($key, $value, $expires_after);
172  }
173  }
174 
185  public function add(string $key, $data): bool {
186  if (!isset($this[$key])) {
187  return $this->save($key, $data);
188  }
189 
190  return false;
191  }
192 
193  // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
194 
205  #[\ReturnTypeWillChange]
206  public function offsetSet($key, $value) {
207  $this->save($key, $value);
208  }
209 
219  #[\ReturnTypeWillChange]
220  public function offsetGet($key) {
221  return $this->load($key);
222  }
223 
233  #[\ReturnTypeWillChange]
234  public function offsetUnset($key) {
235  if (isset($this->$key)) {
236  unset($this->$key);
237  }
238  }
239 
249  #[\ReturnTypeWillChange]
250  public function offsetExists($key) {
251  return isset($this->$key);
252  }
253 }
offsetUnset($key)
Unsets a key.
Definition: ElggCache.php:234
load($key)
Load data from the cache using a given key.
__construct()
Set the constructor.
Definition: ElggCache.php:22
getVariable(string $variable)
Get variables for this cache.
Definition: ElggCache.php:44
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
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
__set(string $key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: ElggCache.php:67
purge()
Purge old/stale contents of the cache.
__unset(string $key)
Supporting unsetting of magic attributes.
Definition: ElggCache.php:89
setVariable(string $variable, $value)
Set a cache variable.
Definition: ElggCache.php:33
disable()
Disable cache Do not write or read from cache.
Definition: ElggCache.php:148
$value
Definition: generic.php:51
offsetExists($key)
Does key exist.
Definition: ElggCache.php:250
enable()
Enable disabled cache.
Definition: ElggCache.php:156
offsetGet($key)
Get the value for specified key.
Definition: ElggCache.php:220
add(string $key, $data)
Add a key only if it doesn&#39;t already exist.
Definition: ElggCache.php:185
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
__isset(string $key)
Supporting isset, using $this->load() with default values.
Definition: ElggCache.php:78
invalidate()
Invalidate the contents of the cache.
offsetSet($key, $value)
Assigns a value for the specified key.
Definition: ElggCache.php:206
clear()
Clear out all the contents of the cache.
populate(array $values, int $expires_after=null)
Populate cache from an array of key => values.
Definition: ElggCache.php:168
__get(string $key)
Class member get overloading, returning key using $this->load defaults.
Definition: ElggCache.php:55
save($key, $data, $expire_after=null)
Save data in a cache.