热搜:NVER node 开发 php

ecshop改了模板类使用memcached之后怎么判断调用成功?

2024-08-15 22:15:01
ecshop改了模板类使用memcached之后怎么判断调用成功?

问题就是这样,
function fetch
function is_cached
改了这两个函数部分
ecshop 自身是不报错了,但是现在就是不知道 ecshop 对缓存调用 成功不?请各位大大pp。help。

/**     * 处理模板文件     *     * @access  public     * @param   string      $filename     * @param   sting      $cache_id     *     * @return  sring     */    function fetch($filename, $cache_id = '')    {        if (!$this->_seterror)        {            error_reporting(E_ALL ^ E_NOTICE);        }        $this->_seterror++;        if (strncmp($filename,'str:', 4) == 0)        {            $out = $this->_eval($this->fetch_str(substr($filename, 4)));        }        else        {            if ($this->_checkfile)            {                if (!file_exists($filename))                {                    $filename = $this->template_dir . '/' . $filename;                }            }            else            {                $filename = $this->template_dir . '/' . $filename;            }            if ($this->direct_output)            {                $this->_current_file = $filename;                $out = $this->_eval($this->fetch_str(file_get_contents($filename)));            }            else            {                if ($cache_id && $this->caching)                {                    $out = $this->template_out;                }                else                {                    if (!in_array($filename, $this->template))                    {                        $this->template[] = $filename;                    }                    $out = $this->make_compiled($filename);                    if ($cache_id)                    {                        $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;                        $data = serialize(array('template' => $this->template, 'expires' => $this->_nowtime + $this->cache_lifetime, 'maketime' => $this->_nowtime));                        $out = str_replace("\r", '', $out);												$memcache = new Memcache;						$memcache->connect("127.0.0.1", 11211);						$CacheID = md5($filename.$cache_id.$cachename);                        while (strpos($out, "\n\n") !== false)                        {                            $out = str_replace("\n\n", "\n", $out);                        }												$memcache->set($CacheID , '<?php exit;?>' . $data . $out , 3600);						                        $this->template = array();                    }                }            }        }        $this->_seterror--;        if (!$this->_seterror)        {            error_reporting($this->_errorlevel);        }        return $out; // 返回html数据    }


/**     * 判断是否缓存     *     * @access  public     * @param   string     $filename     * @param   sting      $cache_id     *     * @return  bool     */    function is_cached($filename, $cache_id = '')    {        $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;				$memcache = new Memcache;		$memcache->connect("127.0.0.1", 11211);		$CacheID = md5($filename.$cache_id.$cachename);		        if ($this->caching == true && $this->direct_output == false)        {			if ($data = $memcache->get($CacheID))            {                $data = substr($data, 13);                $pos  = strpos($data, '<');                $paradata = substr($data, 0, $pos);                $para     = @unserialize($paradata);                if ($para === false || $this->_nowtime > $para['expires'])                {                    $this->caching = false;                    return false;                }                $this->_expires = $para['expires'];                $this->template_out = substr($data, $pos);                foreach ($para['template'] AS $val)                {                    $stat = @stat($val);                    if ($para['maketime'] < $stat['mtime'])                    {                        $this->caching = false;                        return false;                    }                }            }            else            {                $this->caching = false;                return false;            }            return true;        }        else        {            return false;        }    }


回复讨论(解决方案)

对了,是 cls_template.php 这个文件中的函数

你查下数据不就行了

ecshop 缓存 分类信息 失效时间 1小时需要修改的文件 category.php$memcache->set($cache_var , $data , 0, 3600);				|			|		|	|				key			数据	压缩	失效时间(秒)				自行替换 /** * 获得分类的信息 * * @param   integer $cat_id * * @return  voidfunction get_cat_info($cat_id){	return $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') .		" WHERE cat_id = '$cat_id'");}*///mem缓存分类function get_cat_info($cat_id){	$memcache = new Memcache;	$memcache->connect("127.0.0.1", 11211);	$cache_var = 'men_category_info_'.$cat_id;	$data = $memcache->get($cache_var);		if($data === false){		$data = $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') .				" WHERE cat_id = '$cat_id'");		$memcache->set($cache_var , $data , 0, 3600);		return $data;	}else{		return $data;	}}


这样解决了 谢谢

还有好几个文件一样处理
修改修改的文件 includes/cls_template.php
需要改写的文件 includes/lib_base.php
需要修改的文件 category.php