summaryrefslogtreecommitdiff
path: root/includes/objectcache/EhcacheBagOStuff.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/objectcache/EhcacheBagOStuff.php')
-rw-r--r--includes/objectcache/EhcacheBagOStuff.php82
1 files changed, 75 insertions, 7 deletions
diff --git a/includes/objectcache/EhcacheBagOStuff.php b/includes/objectcache/EhcacheBagOStuff.php
index 75aad27a..f86cf157 100644
--- a/includes/objectcache/EhcacheBagOStuff.php
+++ b/includes/objectcache/EhcacheBagOStuff.php
@@ -1,8 +1,31 @@
<?php
+/**
+ * Object caching using the Ehcache RESTful web service.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Cache
+ */
/**
* Client for the Ehcache RESTful web service - http://ehcache.org/documentation/cache_server.html
* TODO: Simplify configuration and add to the installer.
+ *
+ * @ingroup Cache
*/
class EhcacheBagOStuff extends BagOStuff {
var $servers, $cacheName, $connectTimeout, $timeout, $curlOptions,
@@ -10,6 +33,9 @@ class EhcacheBagOStuff extends BagOStuff {
var $curls = array();
+ /**
+ * @param $params array
+ */
function __construct( $params ) {
if ( !defined( 'CURLOPT_TIMEOUT_MS' ) ) {
throw new MWException( __CLASS__.' requires curl version 7.16.2 or later.' );
@@ -36,6 +62,10 @@ class EhcacheBagOStuff extends BagOStuff {
);
}
+ /**
+ * @param $key string
+ * @return bool|mixed
+ */
public function get( $key ) {
wfProfileIn( __METHOD__ );
$response = $this->doItemRequest( $key );
@@ -70,6 +100,12 @@ class EhcacheBagOStuff extends BagOStuff {
return $data;
}
+ /**
+ * @param $key string
+ * @param $value mixed
+ * @param $expiry int
+ * @return bool
+ */
public function set( $key, $value, $expiry = 0 ) {
wfProfileIn( __METHOD__ );
$expiry = $this->convertExpiry( $expiry );
@@ -107,6 +143,11 @@ class EhcacheBagOStuff extends BagOStuff {
return $result;
}
+ /**
+ * @param $key string
+ * @param $time int
+ * @return bool
+ */
public function delete( $key, $time = 0 ) {
wfProfileIn( __METHOD__ );
$response = $this->doItemRequest( $key,
@@ -122,6 +163,10 @@ class EhcacheBagOStuff extends BagOStuff {
return $result;
}
+ /**
+ * @param $key string
+ * @return string
+ */
protected function getCacheUrl( $key ) {
if ( count( $this->servers ) == 1 ) {
$server = reset( $this->servers );
@@ -149,6 +194,13 @@ class EhcacheBagOStuff extends BagOStuff {
return $this->curls[$cacheUrl];
}
+ /**
+ * @param $key string
+ * @param $data
+ * @param $type
+ * @param $ttl
+ * @return int
+ */
protected function attemptPut( $key, $data, $type, $ttl ) {
// In initial benchmarking, it was 30 times faster to use CURLOPT_POST
// than CURLOPT_UPLOAD with CURLOPT_READFUNCTION. This was because
@@ -173,6 +225,10 @@ class EhcacheBagOStuff extends BagOStuff {
}
}
+ /**
+ * @param $key string
+ * @return bool
+ */
protected function createCache( $key ) {
wfDebug( __METHOD__.": creating cache for $key\n" );
$response = $this->doCacheRequest( $key,
@@ -185,21 +241,26 @@ class EhcacheBagOStuff extends BagOStuff {
wfDebug( __CLASS__.": failed to create cache for $key\n" );
return false;
}
- if ( $response['http_code'] == 201 /* created */
- || $response['http_code'] == 409 /* already there */ )
- {
- return true;
- } else {
- return false;
- }
+ return ( $response['http_code'] == 201 /* created */
+ || $response['http_code'] == 409 /* already there */ );
}
+ /**
+ * @param $key string
+ * @param $curlOptions array
+ * @return array|bool|mixed
+ */
protected function doCacheRequest( $key, $curlOptions = array() ) {
$cacheUrl = $this->getCacheUrl( $key );
$curl = $this->getCurl( $cacheUrl );
return $this->doRequest( $curl, $cacheUrl, $curlOptions );
}
+ /**
+ * @param $key string
+ * @param $curlOptions array
+ * @return array|bool|mixed
+ */
protected function doItemRequest( $key, $curlOptions = array() ) {
$cacheUrl = $this->getCacheUrl( $key );
$curl = $this->getCurl( $cacheUrl );
@@ -207,6 +268,13 @@ class EhcacheBagOStuff extends BagOStuff {
return $this->doRequest( $curl, $url, $curlOptions );
}
+ /**
+ * @param $curl
+ * @param $url string
+ * @param $curlOptions array
+ * @return array|bool|mixed
+ * @throws MWException
+ */
protected function doRequest( $curl, $url, $curlOptions = array() ) {
if ( array_diff_key( $curlOptions, $this->curlOptions ) ) {
// var_dump( array_diff_key( $curlOptions, $this->curlOptions ) );