Example #1
0
/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */
function getcacheinfo($name, $filepath = '', $type = 'file', $config = '')
{
    if (!preg_match("/^[a-zA-Z0-9_-]+\$/", $name)) {
        return false;
    }
    if ($filepath != "" && !preg_match("/^[a-zA-Z0-9_-]+\$/", $filepath)) {
        return false;
    }
    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);
}
Example #2
0
/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */
function getcacheinfo($name, $filepath = '', $type = 'file', $config = '')
{
    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);
}
Example #3
0
 function get_content()
 {
     if ($this->settings['cache_expire_time']) {
         /**先从缓存读取数据 缓存不存在或过期时再从表中查询*/
         include_once ROOT_PATH . 'lib/class/cache/cache.class.php';
         $cache_factory = cache_factory::get_instance();
         $cache_type = $this->settings['cache_type'] ? $this->settings['cache_type'] : 'file';
         $cache_driver = $cache_factory->get_cache_driver($cache_type);
         $input = $this->input;
         unset($input['access_token'], $input['lpip']);
         $cache_id = md5(serialize($input));
         $data = $cache_driver->get($cache_id);
         if ($data) {
             $this->addItem($data);
             $this->output();
         }
         /**先从缓存读取数据 缓存不存在或过期时再从表中查询*/
     }
     //$condition = $this->get_condition();
     $offset = $this->input['page'] ? $this->input['page_num'] * ($this->input['page'] - 1) : 0;
     $count = $this->input['page_num'] ? intval($this->input['page_num']) : 20;
     $con = $con_count = $this->con_process();
     $con['offset'] = $offset;
     $con['count'] = $count;
     $content = $this->obj->get_content($con);
     include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
     $this->publishcontent = new publishcontent();
     $content_type = $this->publishcontent->get_all_content_type();
     $pub_content_bundle = array();
     foreach ((array) $content_type as $k => $v) {
         $pub_content_bundle[] = $v['bundle_id'];
     }
     include_once ROOT_PATH . 'lib/class/auth.class.php';
     $this->auth = new Auth();
     $app_info = $this->auth->get_app();
     $module = array();
     foreach ((array) $app_info as $k => $v) {
         if (!empty($v)) {
             $module[$v['bundle']] = $v['name'];
         }
     }
     $cidArr = array();
     $conArr = array();
     $other_content = array();
     foreach ((array) $content as $row) {
         if (!in_array($row['app_bundle'], $pub_content_bundle)) {
             $row['bundle_name'] = $module[$row['app_bundle']];
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $this->settings["App_{$row['app_bundle']}"]['name'];
             }
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $row['app_bundle'];
             }
             $row['content_url'] = $row['url'];
             $row['access_nums'] = $row['num'];
             $other_content[] = $row;
         } else {
             $cidArr[] = $row['cid'];
             $conArr[$row['cid']] = array('access_nums' => $row['num']);
         }
     }
     $cidStr = implode(',', $cidArr);
     $ret = $this->publishcontent->get_content_by_cid($cidStr);
     if (!is_array($ret)) {
         //return array();
     }
     $ret = (array) $ret;
     $arExistIds = array();
     foreach ($ret as $k => $v) {
         $arExistIds[] = $v['cid'];
         $ret[$k]['bundle_name'] = $module[$v['bundle_id']];
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $this->settings["App_{$v['bundle_id']}"]['name'];
         }
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $v['bundle_id'];
         }
         $ret[$k] = array_merge($ret[$k], $conArr[$k]);
     }
     $ret = array_merge($ret, $other_content);
     //发布库删除没有更新统计时条数不准确 下面代码为解决此bug
     //对比cid差集
     $delCid = array_diff($cidArr, $arExistIds);
     //更新已经不存在的内容
     if (!empty($delCid)) {
         $cid = implode(',', $delCid);
         $sql = "UPDATE " . DB_PREFIX . "nums SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
         include_once CUR_CONF_PATH . 'lib/cache.class.php';
         $cache = new CacheFile();
         $table = $cache->get_cache('access_table_name');
         $table = convert_table_name($table);
         if ($table) {
             $table_str = implode(',', $table);
         }
         $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
         $this->db->query($sql);
         $sql = "UPDATE " . DB_PREFIX . "merge SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
     }
     $ret = hg_array_sort($ret, 'access_nums', 'DESC');
     $pagearr = $this->obj->get_content($con_count, 1);
     $pagearr['page_num'] = $count;
     $pagearr['total_num'] = $pagearr['total'];
     $pagearr['total_page'] = ceil($pagearr['total'] / $count);
     $pagearr['current_page'] = floor($offset / $count) + 1;
     $ret = array('content' => array_values($ret), 'page' => $pagearr);
     if ($this->settings['cache_expire_time']) {
         /*将数据写入缓存*/
         $cache_driver->set($cache_id, $ret, $this->settings['cache_expire_time']);
         /*将数据写入缓存*/
     }
     $this->addItem($ret);
     $this->output();
 }