phpcms 添加memcache支持
?
1,修改caches/configs/cache.php
<?php
return array (
'file1' => array (
'type' => 'file',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
'memcache1' => array (
'hostname' => '127.0.0.1',
'port' => 11211,
'timeout' => 0,
'type' => 'memcache',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
)
);
?>
?
2,修改phpcms/libs/functions/globl.func.php ?文件的四個函數(shù)
?
function setcache($name, $data, $filepath='',?$type='memcache', $config='memcache1',?$timeout=0) {
pc_base::load_sys_class('cache_factory','',0);
if($config) {
$cacheconfig = pc_base::load_config('cache');
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->set($name, $data, $timeout, '', $filepath);
}
function getcache($name, $filepath='',?$type='memcache', $config='memcache1') {
pc_base::load_sys_class('cache_factory','',0);
if($config) {
$cacheconfig = pc_base::load_config('cache');
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->get($name, '', '', $filepath);
}
function delcache($name, $filepath='',?$type='memcache', $config='memcache1') {
pc_base::load_sys_class('cache_factory','',0);
if($config) {
$cacheconfig = pc_base::load_config('cache');
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->delete($name, '', '', $filepath);
}
function getcacheinfo($name, $filepath='',?$type='memcache', $config='memcache1') {
pc_base::load_sys_class('cache_factory');
if($config) {
$cacheconfig = pc_base::load_config('cache');
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->cacheinfo($name, '', '', $filepath);
}
3,修改phpcms/libs/classes/cache_memcache.class.php
<?php?
class cache_memcache {
private $memcache = null;
public function __construct() {
$this->memcache = new Memcache;
$this->memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT)or die ("Could not connect");
}
public function memcache() {
$this->__construct();
}
public function get($name, $empty='', $empty='',$filepath) {
$value = $this->memcache->get($name.$filepath);
return $value;
}
public function cacheinfo($name, $empty='', $empty='', $filepath){
$value = $this->memcache->get($name.$filepath);
return $value;
}
public function set($name, $value, $ttl = 3600, $ext1='', $ext2='') {
return $this->memcache->set($name.$ext2, $value, false, $ttl);
}
public function delete($name, $empty='', $empty='', $filepath) {
return $this->memcache->delete($name.$filepath);
}
public function flush() {
return $this->memcache->flush();
}
}
?>
?
?
4,測試調(diào)用文件(保持到網(wǎng)站根目錄查看)
<?php
header('Content-type: text/html; charset=utf8');
echo "<pre>";
$host='127.0.0.1';
$port=11211;
$mem=new Memcache();
$mem->connect($host,$port);
?
$mem->set('var_key', 'some variable', 0, 30);//設(shè)置
$var = $mem->get('var_key');//獲取
echo $var;
$mem->add('xxx','fffffffff',0,80);//添加
$mem->delete('xxx', 10);//刪除
$var = $mem->get('xxx');
echo $var;
?
$items=$mem->getExtendedStats ('items');
$items=$items["$host:$port"]['items'];
foreach($items as $key=>$values){
$number=$key;;
$str=$mem->getExtendedStats ("cachedump",$number,0);
$line=$str["$host:$port"];
if( is_array($line) && count($line)>0){
foreach($line as $key=>$value){
echo $key.'=>';
print_r($mem->get($key));
echo "\r\n"."<br>";
}
}
}
?>
轉(zhuǎn)載于:https://www.cnblogs.com/fslnet/p/4434771.html
總結(jié)
以上是生活随笔為你收集整理的phpcms 添加memcache支持的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Worktile 技术架构概要
- 下一篇: (转)所有iOS设备的屏幕分辨率