From c6210d516c0bac317759fc814717922036440264 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=2E=C3=87a=C4=9Flar=20Onur?= Date: Mon, 8 Nov 2010 17:50:06 -0500 Subject: [PATCH] preliminary memcache support for PHP layer --- php/plc_api.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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; } } -- 2.47.0