Elgg  Version 3.0
ElggCache.php
Go to the documentation of this file.
1 <?php
9 abstract class ElggCache implements \ArrayAccess {
15  private $variables;
16 
20  protected $disabled = false;
21 
25  public function __construct() {
26  $this->variables = [];
27  }
28 
37  public function setVariable($variable, $value) {
38  if (!is_array($this->variables)) {
39  $this->variables = [];
40  }
41 
42  $this->variables[$variable] = $value;
43  }
44 
52  public function getVariable($variable) {
53  if (isset($this->variables[$variable])) {
54  return $this->variables[$variable];
55  }
56 
57  return null;
58  }
59 
67  public function __get($key) {
68  return $this->load($key);
69  }
70 
79  public function __set($key, $value) {
80  $this->save($key, $value);
81  }
82 
90  public function __isset($key) {
91  return (bool) $this->load($key);
92  }
93 
101  public function __unset($key) {
102  return $this->delete($key);
103  }
104 
114  abstract public function save($key, $data, $expire_after = null);
115 
123  abstract public function load($key);
124 
132  abstract public function delete($key);
133 
139  abstract public function clear();
140 
146  public function disable() {
147  $this->disabled = true;
148  }
149 
154  public function enable() {
155  $this->disabled = false;
156  }
157 
166  public function populate($values, $expires_after) {
167  $this->clear();
168  foreach ($values as $key => $value) {
169  $this->save($key, $value, $expires_after);
170  }
171  }
172 
183  public function add($key, $data) {
184  if (!isset($this[$key])) {
185  return $this->save($key, $data);
186  }
187 
188  return false;
189  }
190 
191  // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
192 
203  public function offsetSet($key, $value) {
204  $this->save($key, $value);
205  }
206 
216  public function offsetGet($key) {
217  return $this->load($key);
218  }
219 
229  public function offsetUnset($key) {
230  if (isset($this->$key)) {
231  unset($this->$key);
232  }
233  }
234 
244  public function offsetExists($key) {
245  return isset($this->$key);
246  }
247 }
offsetUnset($key)
Unsets a key.
Definition: ElggCache.php:229
load($key)
Load data from the cache using a given key.
__construct()
Set the constructor.
Definition: ElggCache.php:25
__isset($key)
Supporting isset, using $this->load() with default values.
Definition: ElggCache.php:90
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
populate($values, $expires_after)
Populate cache from an array of key => values.
Definition: ElggCache.php:166
add($key, $data)
Add a key only if it doesn&#39;t already exist.
Definition: ElggCache.php:183
disable()
Disable cache Do not write or read from cache.
Definition: ElggCache.php:146
__get($key)
Class member get overloading, returning key using $this->load defaults.
Definition: ElggCache.php:67
offsetExists($key)
Does key exist.
Definition: ElggCache.php:244
enable()
Enable disabled cache.
Definition: ElggCache.php:154
offsetGet($key)
Get the value for specified key.
Definition: ElggCache.php:216
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
offsetSet($key, $value)
Assigns a value for the specified key.
Definition: ElggCache.php:203
__set($key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: ElggCache.php:79
clear()
Clear out all the contents of the cache.
setVariable($variable, $value)
Set a cache variable.
Definition: ElggCache.php:37
__unset($key)
Supporting unsetting of magic attributes.
Definition: ElggCache.php:101
getVariable($variable)
Get variables for this cache.
Definition: ElggCache.php:52
save($key, $data, $expire_after=null)
Save data in a cache.