Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
ElggCache.php
Go to the documentation of this file.
1 <?php
9 abstract class ElggCache implements \ArrayAccess {
15  private $variables;
16 
20  public function __construct() {
21  $this->variables = array();
22  }
23 
32  public function setVariable($variable, $value) {
33  if (!is_array($this->variables)) {
34  $this->variables = array();
35  }
36 
37  $this->variables[$variable] = $value;
38  }
39 
47  public function getVariable($variable) {
48  if (isset($this->variables[$variable])) {
49  return $this->variables[$variable];
50  }
51 
52  return null;
53  }
54 
62  public function __get($key) {
63  return $this->load($key);
64  }
65 
74  public function __set($key, $value) {
75  $this->save($key, $value);
76  }
77 
85  public function __isset($key) {
86  return (bool)$this->load($key);
87  }
88 
96  public function __unset($key) {
97  return $this->delete($key);
98  }
99 
108  abstract public function save($key, $data);
109 
122  abstract public function load($key, $offset = 0, $limit = null);
123 
131  abstract public function delete($key);
132 
138  abstract public function clear();
139 
150  public function add($key, $data) {
151  if (!isset($this[$key])) {
152  return $this->save($key, $data);
153  }
154 
155  return false;
156  }
157 
158  // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
159 
170  public function offsetSet($key, $value) {
171  $this->save($key, $value);
172  }
173 
183  public function offsetGet($key) {
184  return $this->load($key);
185  }
186 
196  public function offsetUnset($key) {
197  if (isset($this->$key)) {
198  unset($this->$key);
199  }
200  }
201 
211  public function offsetExists($key) {
212  return isset($this->$key);
213  }
214 }
offsetUnset($key)
Unsets a key.
Definition: ElggCache.php:196
__construct()
Set the constructor.
Definition: ElggCache.php:20
__isset($key)
Supporting isset, using $this->load() with default values.
Definition: ElggCache.php:85
$data
Definition: opendd.php:13
$value
Definition: longtext.php:26
if(!$count) $offset
Definition: pagination.php:26
add($key, $data)
Add a key only if it doesn't already exist.
Definition: ElggCache.php:150
__get($key)
Class member get overloading, returning key using $this->load defaults.
Definition: ElggCache.php:62
offsetExists($key)
Does key exist.
Definition: ElggCache.php:211
$limit
Definition: userpicker.php:38
$key
Definition: summary.php:34
save($key, $data)
Save data in a cache.
offsetGet($key)
Get the value for specified key.
Definition: ElggCache.php:183
offsetSet($key, $value)
Assigns a value for the specified key.
Definition: ElggCache.php:170
__set($key, $value)
Class member set overloading, setting a key using $this->save defaults.
Definition: ElggCache.php:74
load($key, $offset=0, $limit=null)
Load data from the cache using a given key.
clear()
Clear out all the contents of the cache.
setVariable($variable, $value)
Set a cache variable.
Definition: ElggCache.php:32
__unset($key)
Supporting unsetting of magic attributes.
Definition: ElggCache.php:96
getVariable($variable)
Get variables for this cache.
Definition: ElggCache.php:47