改造海洋cms文件缓存为Redis缓存系统教程

编辑 /include/common.func.php 文件第1514行,将

function setCache($p_cacheName,$sql="",$arr=""){
    global $dsql,$cfg_iscache,$cfg_cachetime,$cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$p_cacheName.'.inc';
    $mintime = time() - $cfg_cachetime*60;
    if(!file_exists($cacheFile) || ( file_exists($cacheFile) && ($mintime > filemtime($cacheFile)))){
        if (!empty($sql)){
        $dsql->SetQuery($sql);
        $dsql->Execute('hw');
        $cacher=array();
            while($cache=$dsql->GetObject('hw'))
            {
            $cacher[]=$cache;
            }
        }else{
            $cacher=$arr;
        }
        if (!empty($p_cacheName)){
            $fp = fopen($cacheFile,'w') or die("Write Cache File Error! ");
            fwrite($fp,serialize($cacher));
            fclose($fp);
        }
        unset($cacher);
    }
}

function getCache($p_cacheName){
    global $cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$p_cacheName.'.inc';
    if(file_exists($cacheFile)){
        return unserialize(file_get_contents($cacheFile));
    }else{
        return array();
    }
}

修改为:

function setCache($p_cacheName,$sql="",$arr=""){
        global $dsql,$cfg_iscache,$cfg_cachetime,$cfg_cachemark;
        $p_cacheName=$cfg_cachemark.$p_cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        $ttl=$redis->TTL($p_cacheName);
        if ($ttl < 1 ){
                if (!empty($sql)){
                        $dsql->SetQuery($sql);
                        $dsql->Execute('hw');
                        $cacher=array();
                  while($cache=$dsql->GetObject('hw'))
                        {
                        $cacher[]=$cache;
                        }
                }else{
                        $cacher=$arr;
                }
                if (!empty($p_cacheName)){
                        $redis->SETEX($p_cacheName,$cfg_cachetime*60,serialize($cacher));
                }
                unset($cacher);
        }
}


function getCache($p_cacheName){
        global $cfg_cachemark;
        $p_cacheName=$cfg_cachemark.$p_cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        $ttl=$redis->TTL($p_cacheName);
        if ($ttl > 0 ){
                return unserialize($redis->GET($p_cacheName));
        }else{
                return array();
        }
}

编辑 /include/common.func.php 文件第2403行,将

function chkFileCache($cacheName)
{
    global $cfg_cachetime,$cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$cacheName.'.inc';
    $mintime = time() - $cfg_cachetime*60;
    if(!file_exists($cacheFile) || ( file_exists($cacheFile) && ($mintime > filemtime($cacheFile)))){
        return false;
    }else{
        return true;
    }
}


function setFileCache($cacheName,$cacheValue)
{
    global $cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$cacheName.'.inc';
    if($cacheName){
        $fp = fopen($cacheFile,'w') or dir("Write Cache File Error! ");
        fwrite($fp,$cacheValue);
        fclose($fp);
    }
}


function getFileCache($cacheName)
{
    global $cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$cacheName.'.inc';
    if(file_exists($cacheFile)){
        @$fp = fopen($cacheFile,'r');
        @$cacheValue = fread($fp,filesize($cacheFile));
        @fclose($fp);
        return $cacheValue;
    }else{
        return ""
    }
}

修改为:

function chkFileCache($cacheName)
{
        global $cfg_cachemark;
        $cacheName=$cfg_cachemark.$cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        $ttl=$redis->TTL($cacheName);
        if ($ttl > 0){
                return true;
        }else{
                return false;
        }
}
function setFileCache($cacheName,$cacheValue)
{
        global $cfg_cachetime,$cfg_cachemark;
        $cacheName=$cfg_cachemark.$cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        if ($redis->SETEX($cacheName,$cfg_cachetime*60,$cacheValue)){
                return true;
        }else{
                return false;
        }
}

function getFileCache($cacheName)
{
        global $cfg_cachemark;
        $cacheName=$cfg_cachemark.$cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        return $redis->GET($cacheName);
}

消息盒子
# 您需要首次评论以获取消息 #
# 您需要首次评论以获取消息 #

只显示最新10条未读和已读信息