Elgg  Version master
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 }
add(string $key, $data)
Add a key only if it doesn&#39;t already exist.
Definition: BaseCache.php:180
enable()
Enable disabled cache.
Definition: BaseCache.php:151
__isset(string $key)
Supporting isset, using $this->load() with default values.
Definition: BaseCache.php:73
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(empty($count)) $offset
Definition: pagination.php:26
clear()
Clear out all the contents of the cache.
$value
Definition: generic.php:51
disable()
Disable cache Do not write or read from cache.
Definition: BaseCache.php:143
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
offsetUnset($offset)
Unsets a key.
Definition: BaseCache.php:229
__set(string $key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: BaseCache.php:62
offsetSet($offset, $value)
Assigns a value for the specified key.
Definition: BaseCache.php:201
__unset(string $key)
Supporting unsetting of magic attributes.
Definition: BaseCache.php:84
load($key)
Load data from the cache using a given key.
The Elgg cache base class.
Definition: BaseCache.php:9
invalidate()
Invalidate the contents of the cache.
__get(string $key)
Class member get overloading, returning key using $this->load defaults.
Definition: BaseCache.php:50
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
setVariable(string $variable, $value)
Set a cache variable.
Definition: BaseCache.php:28
offsetExists($offset)
Does key exist.
Definition: BaseCache.php:245
purge()
Purge old/stale contents of the cache.
offsetGet($offset)
Get the value for specified key.
Definition: BaseCache.php:215
getVariable(string $variable)
Get variables for this cache.
Definition: BaseCache.php:39
save($key, $data, $expire_after=null)
Save data in a cache.
populate(array $values, int $expires_after=null)
Populate cache from an array of key => values.
Definition: BaseCache.php:163