return ((float) $usec + (float) $sec);
}
+ function generateKey($method, $args)
+ {
+ $excluded_API_functions = array("AddSession", "GetSession", "DeleteSession", "AuthCheck", "VerifyPerson");
+
+ if (array_search($method, $excluded_API_functions))
+ return NULL;
+
+ // Key is the md5sum of method + (arguments list - session variables)
+ $arguments = $args;
+ unset($arguments[0]);
+ return md5($method . serialize($arguments));
+ }
+
+ function lookup($method, $args = NULL)
+ {
+ $key = $this->generateKey($method, $args);
+ if ($key == NULL)
+ return NULL;
+
+ $memcache = new Memcache;
+ $memcache->connect($this->server, 11211) or die ("Could not connect");
+
+ $result = $memcache->get($key);
+
+ if ($result == FALSE) {
+ $this->error_log ("MEMCACHE: " . $method . " with " . count($args) . " args lookup failed for " . $key);
+ }
+ else
+ {
+ $this->error_log ("MEMCACHE: " . $method . " with " . count($args) . " args lookup succeded for " . $key);
+ if (gettype($result) == "array")
+ return $result;
+ else if ($result == "NULL")
+ return NULL;
+ else
+ return unserialize($result);
+ }
+ return NULL;
+ }
+
function call($method, $args = NULL)
{
if ($this->multicall) {
$this->calls[] = array ('methodName' => $method,
- 'params' => $args);
+ 'params' => $args);
return NULL;
} else {
- return $this->internal_call ($method, $args, 3);
+ $result = $this->lookup($method, $args);
+ if ($result == NULL)
+ {
+ $memcache = new Memcache;
+ $memcache->connect($this->server, 11211) or die ("Could not connect");
+
+ $result = $this->internal_call ($method, $args, 3);
+
+ $key = $this->generateKey($method, $args);
+ if ($key != NULL)
+ {
+ $memcache->set($key, $result == NULL ? "NULL" : $result, MEMCACHE_COMPRESSED, 600);
+ }
+ }
+ return $result;
}
}