From: S.Çağlar Onur Date: Mon, 8 Nov 2010 22:50:06 +0000 (-0500) Subject: preliminary memcache support for PHP layer X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=c6210d516c0bac317759fc814717922036440264;p=plcapi.git preliminary memcache support for PHP layer --- diff --git a/php/plc_api.php b/php/plc_api.php index cb7257ad..232aff22 100644 --- a/php/plc_api.php +++ b/php/plc_api.php @@ -76,12 +76,38 @@ class PLCAPI function call($method, $args = NULL) { + $memcache = new Memcache; + $memcache->connect($this->server, 11211) or die ("Could not connect"); + + $key = $method; + if (gettype($args[1]) == "array") + { + foreach(array_values($args[1]) as $arg) + $key .= $arg; + } + else + $key .= $args[1]; + + $result = $memcache->get($key); + if ($result != FALSE) { + if ($result == "NULL") + return NULL; + if (gettype($result) == "array") + return $result; + else + return unserialize($result); + } + if ($this->multicall) { $this->calls[] = array ('methodName' => $method, 'params' => $args); return NULL; } else { - return $this->internal_call ($method, $args, 3); + $result = $this->internal_call ($method, $args, 3); + if ($result == NULL) + $result = "NULL"; + $memcache->set($key, $result, false, 500); + return $result; } }