git://git.onelab.eu
/
plcapi.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
edbba27
)
preliminary memcache support for PHP layer
author
S.Çağlar Onur
<caglar@cs.princeton.edu>
Mon, 8 Nov 2010 22:50:06 +0000
(17:50 -0500)
committer
S.Çağlar Onur
<caglar@cs.princeton.edu>
Mon, 8 Nov 2010 22:50:06 +0000
(17:50 -0500)
php/plc_api.php
patch
|
blob
|
history
diff --git
a/php/plc_api.php
b/php/plc_api.php
index
cb7257a
..
232aff2
100644
(file)
--- a/
php/plc_api.php
+++ b/
php/plc_api.php
@@
-76,12
+76,38
@@
class PLCAPI
function call($method, $args = NULL)
{
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 {
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;
}
}
}
}