Elgg  Version 5.1
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 $variables = [];
17 
21  protected $disabled = false;
22 
26  public function __construct() {
27  }
28 
37  public function setVariable(string $variable, $value): void {
38  $this->variables[$variable] = $value;
39  }
40 
48  public function getVariable(string $variable) {
49  return $this->variables[$variable] ?? null;
50  }
51 
59  public function __get(string $key) {
60  return $this->load($key);
61  }
62 
71  public function __set(string $key, $value): void {
72  $this->save($key, $value);
73  }
74 
82  public function __isset(string $key): bool {
83  return (bool) $this->load($key);
84  }
85 
93  public function __unset(string $key): void {
94  $this->delete($key);
95  }
96 
106  abstract public function save($key, $data, $expire_after = null);
107 
115  abstract public function load($key);
116 
124  abstract public function delete($key);
125 
131  abstract public function clear();
132 
138  abstract public function invalidate();
139 
145  abstract public function purge();
146 
152  public function disable(): void {
153  $this->disabled = true;
154  }
155 
160  public function enable(): void {
161  $this->disabled = false;
162  }
163 
172  public function populate(array $values, int $expires_after = null): void {
173  $this->clear();
174  foreach ($values as $key => $value) {
175  $this->save($key, $value, $expires_after);
176  }
177  }
178 
189  public function add(string $key, $data): bool {
190  if (!isset($this[$key])) {
191  return $this->save($key, $data);
192  }
193 
194  return false;
195  }
196 
197  // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
198 
209  #[\ReturnTypeWillChange]
210  public function offsetSet($offset, $value) {
211  $this->save($offset, $value);
212  }
213 
223  #[\ReturnTypeWillChange]
224  public function offsetGet($offset) {
225  return $this->load($offset);
226  }
227 
237  #[\ReturnTypeWillChange]
238  public function offsetUnset($offset) {
239  if (isset($this->$offset)) {
240  unset($this->$offset);
241  }
242  }
243 
253  #[\ReturnTypeWillChange]
254  public function offsetExists($offset) {
255  return isset($this->$offset);
256  }
257 }
add(string $key, $data)
Add a key only if it doesn&#39;t already exist.
Definition: BaseCache.php:189
enable()
Enable disabled cache.
Definition: BaseCache.php:160
__isset(string $key)
Supporting isset, using $this->load() with default values.
Definition: BaseCache.php:82
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.
__construct()
Set the constructor.
Definition: BaseCache.php:26
$value
Definition: generic.php:51
disable()
Disable cache Do not write or read from cache.
Definition: BaseCache.php:152
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
offsetUnset($offset)
Unsets a key.
Definition: BaseCache.php:238
__set(string $key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: BaseCache.php:71
offsetSet($offset, $value)
Assigns a value for the specified key.
Definition: BaseCache.php:210
__unset(string $key)
Supporting unsetting of magic attributes.
Definition: BaseCache.php:93
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:59
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:37
offsetExists($offset)
Does key exist.
Definition: BaseCache.php:254
purge()
Purge old/stale contents of the cache.
offsetGet($offset)
Get the value for specified key.
Definition: BaseCache.php:224
getVariable(string $variable)
Get variables for this cache.
Definition: BaseCache.php:48
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:172