Elgg  Version 1.9
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 
24  // @codingStandardsIgnoreStart
35  public function set_variable($variable, $value) {
36  elgg_deprecated_notice('ElggCache::set_variable() is deprecated by ElggCache::setVariable()', 1.8);
37  $this->setVariable($variable, $value);
38  }
39  // @codingStandardsIgnoreEnd
40 
49  public function setVariable($variable, $value) {
50  if (!is_array($this->variables)) {
51  $this->variables = array();
52  }
53 
54  $this->variables[$variable] = $value;
55  }
56 
57  // @codingStandardsIgnoreStart
67  public function get_variable($variable) {
68  elgg_deprecated_notice('ElggCache::get_variable() is deprecated by ElggCache::getVariable()', 1.8);
69  return $this->getVariable($variable);
70  }
71  // @codingStandardsIgnoreEnd
72 
80  public function getVariable($variable) {
81  if (isset($this->variables[$variable])) {
82  return $this->variables[$variable];
83  }
84 
85  return null;
86  }
87 
95  public function __get($key) {
96  return $this->load($key);
97  }
98 
107  public function __set($key, $value) {
108  $this->save($key, $value);
109  }
110 
118  public function __isset($key) {
119  return (bool)$this->load($key);
120  }
121 
129  public function __unset($key) {
130  return $this->delete($key);
131  }
132 
141  abstract public function save($key, $data);
142 
155  abstract public function load($key, $offset = 0, $limit = null);
156 
164  abstract public function delete($key);
165 
171  abstract public function clear();
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
__construct()
Set the constructor.
Definition: ElggCache.php:20
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
__isset($key)
Supporting isset, using $this->load() with default values.
Definition: ElggCache.php:118
$data
Definition: opendd.php:13
$value
Definition: longtext.php:29
add($key, $data)
Add a key only if it doesn&#39;t already exist.
Definition: ElggCache.php:183
__get($key)
Class member get overloading, returning key using $this->load defaults.
Definition: ElggCache.php:95
get_variable($variable)
Get variables for this cache.
Definition: ElggCache.php:67
offsetExists($key)
Does key exist.
Definition: ElggCache.php:244
$limit
Definition: userpicker.php:33
$key
Definition: summary.php:34
save($key, $data)
Save data in a cache.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
offsetGet($key)
Get the value for specified key.
Definition: ElggCache.php:216
set_variable($variable, $value)
Set a cache variable.
Definition: ElggCache.php:35
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:107
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:49
__unset($key)
Supporting unsetting of magic attributes.
Definition: ElggCache.php:129
getVariable($variable)
Get variables for this cache.
Definition: ElggCache.php:80