aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggMemcache.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
commit7ddd9521b3f3a397da3b0a6b56238d31414eb4be (patch)
tree6eb6a9a51db5fa0f5d3cc2ec6de29b9e258b12a1 /engine/classes/ElggMemcache.php
parentbd3484417d170e62bc94e9db81d4ad37e8ddee6a (diff)
downloadelgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.gz
elgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.bz2
Standardized code in all of core, not including language files, tests, or core mods.
git-svn-id: http://code.elgg.org/elgg/trunk@7124 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggMemcache.php')
-rw-r--r--engine/classes/ElggMemcache.php73
1 files changed, 66 insertions, 7 deletions
diff --git a/engine/classes/ElggMemcache.php b/engine/classes/ElggMemcache.php
index 070100586..e0d8e7bee 100644
--- a/engine/classes/ElggMemcache.php
+++ b/engine/classes/ElggMemcache.php
@@ -1,6 +1,9 @@
<?php
/**
* Memcache wrapper class.
+ *
+ * @package Elgg.Core
+ * @subpackage Memcache
*/
class ElggMemcache extends ElggSharedMemoryCache {
/**
@@ -27,7 +30,8 @@ class ElggMemcache extends ElggSharedMemoryCache {
/**
* Connect to memcache.
*
- * @param string $cache_id The namespace for this cache to write to - note, namespaces of the same name are shared!
+ * @param string $namespace The namespace for this cache to write to -
+ * note, namespaces of the same name are shared!
*/
function __construct($namespace = 'default') {
global $CONFIG;
@@ -81,7 +85,12 @@ class ElggMemcache extends ElggSharedMemoryCache {
// Get version
$this->version = $this->memcache->getVersion();
if (version_compare($this->version, ElggMemcache::$MINSERVERVERSION, '<')) {
- throw new ConfigurationException(sprintf(elgg_echo('memcache:versiontoolow'), ElggMemcache::$MINSERVERVERSION, $this->version));
+ $msg = sprintf(elgg_echo('memcache:versiontoolow'),
+ ElggMemcache::$MINSERVERVERSION,
+ $this->version
+ );
+
+ throw new ConfigurationException($msg);
}
// Set some defaults
@@ -94,6 +103,8 @@ class ElggMemcache extends ElggSharedMemoryCache {
* Set the default expiry.
*
* @param int $expires The lifetime as a unix timestamp or time from now. Defaults forever.
+ *
+ * @return void
*/
public function setDefaultExpiry($expires = 0) {
$this->expires = $expires;
@@ -103,21 +114,46 @@ class ElggMemcache extends ElggSharedMemoryCache {
* Combine a key with the namespace.
* Memcache can only accept <250 char key. If the given key is too long it is shortened.
*
+ * @deprecated 1.8 Use ElggMemcache::_makeMemcacheKey()
+ *
* @param string $key The key
+ *
* @return string The new key.
*/
private function make_memcache_key($key) {
+ elgg_deprecated_notice('ElggMemcache::make_memcache_key() is deprecated by ::_makeMemcacheKey()', 1.8);
+
+ return $this->_makeMemcacheKey($key);
+ }
+
+ /**
+ * Combine a key with the namespace.
+ * Memcache can only accept <250 char key. If the given key is too long it is shortened.
+ *
+ * @param string $key The key
+ *
+ * @return string The new key.
+ */
+ private function _makeMemcacheKey($key) {
$prefix = $this->getNamespace() . ":";
- if (strlen($prefix.$key)> 250) {
+ if (strlen($prefix . $key) > 250) {
$key = md5($key);
}
- return $prefix.$key;
+ return $prefix . $key;
}
+ /**
+ * Saves a name and value to the cache
+ *
+ * @param string $key Name
+ * @param string $data Value
+ *
+ * @return bool
+ */
public function save($key, $data) {
- $key = $this->make_memcache_key($key);
+ $key = $this->_makeMemcacheKey($key);
$result = $this->memcache->set($key, $data, null, $this->expires);
if (!$result) {
@@ -127,8 +163,17 @@ class ElggMemcache extends ElggSharedMemoryCache {
return $result;
}
+ /**
+ * Retrieves data.
+ *
+ * @param string $key Name of data to retrieve
+ * @param int $offset Offset
+ * @param int $limit Limit
+ *
+ * @return mixed
+ */
public function load($key, $offset = 0, $limit = null) {
- $key = $this->make_memcache_key($key);
+ $key = $this->_makeMemcacheKey($key);
$result = $this->memcache->get($key);
if (!$result) {
@@ -138,12 +183,26 @@ class ElggMemcache extends ElggSharedMemoryCache {
return $result;
}
+ /**
+ * Delete data
+ *
+ * @param string $key Name of data
+ *
+ * @return bool
+ */
public function delete($key) {
- $key = $this->make_memcache_key($key);
+ $key = $this->_makeMemcacheKey($key);
return $this->memcache->delete($key, 0);
}
+ /**
+ * Clears the entire cache?
+ *
+ * @todo write or remove.
+ *
+ * @return true
+ */
public function clear() {
// DISABLE clearing for now - you must use delete on a specific key.
return true;