解释的文字有空再写,代码如下:
复制PHP内容到剪贴板
PHP代码:
<?php
class Cache {
private $conn = new Memcache();
public __construct($server, $port) {
$this->conn->connect($server, $port);
}
public function get_ts($key) {
$result = $this->conn->$get($key);
if ($result === false) {
if ($this->conn->add($key . "__LOCK", true) != false) {
return false;
} else {
int $timeout = 10000;
while ($result = $this->conn->get($key)) {
usleep(100);
$timeout -= 100;
if ($timeout < 0) {
return false;
}
}
return $result;
}
} else {
return $result;
}
}
public function set_ts($key, $var, $gzip=0, $expire=0) {
$result = $this->conn->set($key, $var, $gzip, $expire);
$this->conn->delete($key . "__LOCK");
return $result;
}
}
?>