您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程

phpcms添加memcache支持的代码示例

映易2025-05-21phpcms教程已有人查阅

导读2,修改phpcms/libs/functions/globl.func.php 文件的四个函数3,修改phpcms/libs/classes/cache_memcache.class.php

<color=rgba(0,]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 文件的四个函数
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,测试调用文件(保持到网站根目录查看)
<?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);//设置
$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>";
}
}
}
?>

本文标签:

很赞哦! ()

相关源码

  • (PC+WAP)绿色环保建筑设备通用行业pbootcms源码下载通过模块调整可适配园林景观、装配式建筑、绿色装修等生态建设相关领域。预制绿色建材展示、能耗模拟等专业模块,集成项目案例、环保工艺等建筑行业特色内容结构,测试数据包含LEED认证体系查看源码
  • WordPress主题模板JustNews资讯博客类源码V5.2.2JustNews主题针对博客创作、自媒体运营及资讯发布类网站的需求而设计,提供专业的内容展示与管理方案。该主题集成前端用户中心功能,支持用户在前端界面发布和投稿文章,操作流程简洁高效。查看源码
  • 帝国cms7.5游戏门户H5小游戏网站模板源码免费下载基于帝国CMS7.5开发的H5游戏门户模板,为在线游戏平台设计。支持PC端与移动端同步生成,打造完整的游戏娱乐体验平台。查看源码
  • (自适应)简繁双语机械矿山矿石五金设备pbootcms源码下载本模板基于PbootCMS开发,主要面向机械五金、矿山矿石设备等行业,支持简体中文和繁体中文双语切换。采用响应式布局技术,确保在各种设备上都能获得良好的浏览体验。模板设计注重展示工业设备的专业性和技术特点,帮助企业建立可靠的线上展示平台。查看源码
  • (自适应)橙色家政服务清洁保洁服务pbootcms网站模板源码下载模板核心价值:基于PbootCMS内核开发的家政服务类网站模板,通过模块化设计展现服务项目、团队风采、服务案例等核心板块,突出时效预约、服务标准化展示等家政行业特性。查看源码
  • (自适应响应式)绿色环保材料设备科技类营销型网站pbootcms源码下载本模板基于PbootCMS开发,主要面向环保设备、环保材料及相关科技企业。采用HTML5+CSS3技术构建,具备响应式特性,确保在各类设备上均有良好展示效果。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐