aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggCache.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes/ElggCache.php')
-rw-r--r--engine/classes/ElggCache.php137
1 files changed, 111 insertions, 26 deletions
diff --git a/engine/classes/ElggCache.php b/engine/classes/ElggCache.php
index a494471b9..909eab39b 100644
--- a/engine/classes/ElggCache.php
+++ b/engine/classes/ElggCache.php
@@ -3,12 +3,10 @@
* ElggCache The elgg cache superclass.
* This defines the interface for a cache (wherever that cache is stored).
*
- * @package Elgg.Core
+ * @package Elgg.Core
* @subpackage Cache
*/
-abstract class ElggCache implements
- // Override for array access
- ArrayAccess {
+abstract class ElggCache implements ArrayAccess {
/**
* Variables for the cache object.
*
@@ -23,13 +21,32 @@ abstract class ElggCache implements
$this->variables = array();
}
+ // @codingStandardsIgnoreStart
/**
* Set a cache variable.
*
- * @param string $variable
- * @param string $value
+ * @param string $variable Name
+ * @param string $value Value
+ *
+ * @return void
+ *
+ * @deprecated 1.8 Use ElggCache:setVariable()
*/
public function set_variable($variable, $value) {
+ elgg_deprecated_notice('ElggCache::set_variable() is deprecated by ElggCache::setVariable()', 1.8);
+ $this->setVariable($variable, $value);
+ }
+ // @codingStandardsIgnoreEnd
+
+ /**
+ * Set a cache variable.
+ *
+ * @param string $variable Name
+ * @param string $value Value
+ *
+ * @return void
+ */
+ public function setVariable($variable, $value) {
if (!is_array($this->variables)) {
$this->variables = array();
}
@@ -37,13 +54,30 @@ abstract class ElggCache implements
$this->variables[$variable] = $value;
}
+ // @codingStandardsIgnoreStart
/**
* Get variables for this cache.
*
- * @param string $variable
- * @return mixed The variable or null;
+ * @param string $variable Name
+ *
+ * @return mixed The value or null;
+ *
+ * @deprecated 1.8 Use ElggCache::getVariable()
*/
public function get_variable($variable) {
+ elgg_deprecated_notice('ElggCache::get_variable() is deprecated by ElggCache::getVariable()', 1.8);
+ return $this->getVariable($variable);
+ }
+ // @codingStandardsIgnoreEnd
+
+ /**
+ * Get variables for this cache.
+ *
+ * @param string $variable Name
+ *
+ * @return mixed The variable or null;
+ */
+ public function getVariable($variable) {
if (isset($this->variables[$variable])) {
return $this->variables[$variable];
}
@@ -54,7 +88,8 @@ abstract class ElggCache implements
/**
* Class member get overloading, returning key using $this->load defaults.
*
- * @param string $key
+ * @param string $key Name
+ *
* @return mixed
*/
function __get($key) {
@@ -64,8 +99,9 @@ abstract class ElggCache implements
/**
* Class member set overloading, setting a key using $this->save defaults.
*
- * @param string $key
- * @param mixed $value
+ * @param string $key Name
+ * @param mixed $value Value
+ *
* @return mixed
*/
function __set($key, $value) {
@@ -76,6 +112,7 @@ abstract class ElggCache implements
* Supporting isset, using $this->load() with default values.
*
* @param string $key The name of the attribute or metadata.
+ *
* @return bool
*/
function __isset($key) {
@@ -86,6 +123,8 @@ abstract class ElggCache implements
* Supporting unsetting of magic attributes.
*
* @param string $key The name of the attribute or metadata.
+ *
+ * @return bool
*/
function __unset($key) {
return $this->delete($key);
@@ -94,8 +133,9 @@ abstract class ElggCache implements
/**
* Save data in a cache.
*
- * @param string $key
- * @param string $data
+ * @param string $key Name
+ * @param string $data Value
+ *
* @return bool
*/
abstract public function save($key, $data);
@@ -103,9 +143,13 @@ abstract class ElggCache implements
/**
* Load data from the cache using a given key.
*
- * @param string $key
- * @param int $offset
- * @param int $limit
+ * @todo $offset is a horrible variable name because it creates confusion
+ * with the ArrayAccess methods
+ *
+ * @param string $key Name
+ * @param int $offset Offset
+ * @param int $limit Limit
+ *
* @return mixed The stored data or false.
*/
abstract public function load($key, $offset = 0, $limit = null);
@@ -113,7 +157,8 @@ abstract class ElggCache implements
/**
* Invalidate a key
*
- * @param string $key
+ * @param string $key Name
+ *
* @return bool
*/
abstract public function delete($key);
@@ -121,16 +166,18 @@ abstract class ElggCache implements
/**
* Clear out all the contents of the cache.
*
+ * @return bool
*/
abstract public function clear();
/**
* Add a key only if it doesn't already exist.
- * Implemented simply here, if you extend this class and your caching engine provides a better way then
- * override this accordingly.
+ * Implemented simply here, if you extend this class and your caching engine
+ * provides a better way then override this accordingly.
+ *
+ * @param string $key Name
+ * @param string $data Value
*
- * @param string $key
- * @param string $data
* @return bool
*/
public function add($key, $data) {
@@ -142,21 +189,59 @@ abstract class ElggCache implements
}
// ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
+
+ /**
+ * Assigns a value for the specified key
+ *
+ * @see ArrayAccess::offsetSet()
+ *
+ * @param mixed $key The key (offset) to assign the value to.
+ * @param mixed $value The value to set.
+ *
+ * @return void
+ */
function offsetSet($key, $value) {
$this->save($key, $value);
}
+ /**
+ * Get the value for specified key
+ *
+ * @see ArrayAccess::offsetGet()
+ *
+ * @param mixed $key The key (offset) to retrieve.
+ *
+ * @return mixed
+ */
function offsetGet($key) {
return $this->load($key);
}
+ /**
+ * Unsets a key.
+ *
+ * @see ArrayAccess::offsetUnset()
+ *
+ * @param mixed $key The key (offset) to unset.
+ *
+ * @return void
+ */
function offsetUnset($key) {
- if ( isset($this->key) ) {
- unset($this->key);
+ if (isset($this->$key)) {
+ unset($this->$key);
}
}
- function offsetExists($offset) {
- return isset($this->$offset);
+ /**
+ * Does key exist
+ *
+ * @see ArrayAccess::offsetExists()
+ *
+ * @param mixed $key A key (offset) to check for.
+ *
+ * @return bool
+ */
+ function offsetExists($key) {
+ return isset($this->$key);
}
-} \ No newline at end of file
+}