2016-12-15 08:20:54 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [Discuz!] (C)2001-2099 Comsenz Inc.
|
|
|
|
* This is NOT a freeware, use is subject to license terms
|
|
|
|
*
|
|
|
|
* $Id: memory_driver_memcache.php 27449 2012-02-01 05:32:35Z zhangguosheng $
|
|
|
|
*/
|
2017-02-07 23:41:58 -05:00
|
|
|
if (!defined('IN_DISCUZ')) {
|
2016-12-15 08:20:54 -05:00
|
|
|
exit('Access Denied');
|
|
|
|
}
|
|
|
|
|
2017-02-07 23:41:58 -05:00
|
|
|
class memory_driver_memcache {
|
|
|
|
|
|
|
|
public $cacheName = 'MemCache';
|
2016-12-15 08:20:54 -05:00
|
|
|
public $enable;
|
|
|
|
public $obj;
|
|
|
|
|
2017-02-07 23:41:58 -05:00
|
|
|
public function env() {
|
|
|
|
return extension_loaded('memcache');
|
|
|
|
}
|
|
|
|
|
2016-12-15 08:20:54 -05:00
|
|
|
public function init($config) {
|
2017-02-07 23:41:58 -05:00
|
|
|
if (!$this->env()) {
|
|
|
|
$this->enable = false;
|
2017-02-12 23:38:53 -05:00
|
|
|
return;
|
2017-02-07 23:41:58 -05:00
|
|
|
}
|
|
|
|
if (!empty($config['server'])) {
|
2016-12-15 08:20:54 -05:00
|
|
|
$this->obj = new Memcache;
|
2017-02-07 23:41:58 -05:00
|
|
|
if ($config['pconnect']) {
|
2016-12-15 08:20:54 -05:00
|
|
|
$connect = @$this->obj->pconnect($config['server'], $config['port']);
|
|
|
|
} else {
|
|
|
|
$connect = @$this->obj->connect($config['server'], $config['port']);
|
|
|
|
}
|
|
|
|
$this->enable = $connect ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($key) {
|
|
|
|
return $this->obj->get($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMulti($keys) {
|
|
|
|
return $this->obj->get($keys);
|
|
|
|
}
|
2017-02-07 23:41:58 -05:00
|
|
|
|
2016-12-15 08:20:54 -05:00
|
|
|
public function set($key, $value, $ttl = 0) {
|
|
|
|
return $this->obj->set($key, $value, MEMCACHE_COMPRESSED, $ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rm($key) {
|
|
|
|
return $this->obj->delete($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clear() {
|
|
|
|
return $this->obj->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function inc($key, $step = 1) {
|
|
|
|
return $this->obj->increment($key, $step);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dec($key, $step = 1) {
|
|
|
|
return $this->obj->decrement($key, $step);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|