当前位置: 首页>>代码示例>>PHP>>正文


PHP setCache函数代码示例

本文整理汇总了PHP中setCache函数的典型用法代码示例。如果您正苦于以下问题:PHP setCache函数的具体用法?PHP setCache怎么用?PHP setCache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setCache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mysql_query_cache

function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
    //如果返回false,此时就需要直接从数据库中获取数据了。
    //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
    //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
    //memcached处理时输出的相关信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = $linkIdentifier != false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql);
        //读取数据库,并将结果放入$cache数组中
        if (is_resource($r) && ($rows = mysql_num_rows($r)) != 0) {
            for ($i = 0; $i < $rows; $i++) {
                $fields = mysql_num_fields($r);
                $row = mysql_fetch_array($r);
                for ($j = 0; $j < $fields; $j++) {
                    if ($i == 0) {
                        $columns[$j] = mysql_field_name($r, $j);
                    }
                    $cache[$i][$columns[$j]] = $row[$j];
                }
            }
            //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
            //如果开启了服务器的话,数据将会被缓存到memcached服务器中
            if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
                # If we get here, there isn’t a memcache daemon running or responding
            }
        }
    }
    return $cache;
}
开发者ID:siriushr,项目名称:hustoj,代码行数:31,代码来源:memcache.php

示例2: SetDetail

  /**
   * 产品信息缓存
   */
  function SetDetail(){
    $ids = $_REQUEST['id'];
	$data['id'] = array('in',explode(',',$ids));
    $list = $this->db->where($data)->select();
	$pmodel = M('Pic');
	C('DATA_CACHE_TYPE','File');
	foreach($list as $vo){
		$p_data['source'] = 'Product';
		$p_data['sourceid'] = $vo['id'];
		$pics = $pmodel->field('domain,filepath,is_thumb')->where($p_data)->select();
		$options['dir'] = get_dir($vo['id']);
		$vo['imgs'] = $pics;
		setCache('detail',$vo,0,$options);
	}
	  foreach($list as $array){
	    $data[$array['id']] = $array;
	  }
	  if($_POST['from']=='self'){
	    return $data;exit;
	  }
	  $return = $this->SetCache('detail',$vo);
	  if($return){
	    $msg['error_code'] = 0;
	  }else{
	    $msg['error_code'] = 8002;
	  }
	  if($_POST['status'])$msg['data'] = $data;
	  echo json_encode($msg);exit;
  }
开发者ID:8yong8,项目名称:vshop,代码行数:32,代码来源:ProductAction.class.php

示例3: getTodayImage

/**
 * 取得今天要顯示的圖片
 * @return 圖片的完整路徑 (含檔名)
 *     FALSE: 找不到圖片
 **/
function getTodayImage($orgimg)
{
    global $chroot, $imgext;
    $dir = $chroot;
    $now = date('Ymd');
    $imglst = array();
    foreach (array_keys($imgext) as $ext) {
        foreach (glob($dir . "*.{$ext}") as $filename) {
            $name = basename($filename, ".{$ext}");
            if (!is_numeric($name) || strlen($name) != 8) {
                continue;
            }
            if (strcmp($now, $name) < 0) {
                continue;
            }
            $imglst[$name] = $filename;
        }
    }
    if (count($imglst) <= 0) {
        setCache($orgimg);
        return FALSE;
    } else {
        krsort($imglst);
        $img = array_shift($imglst);
        setCache($img);
        return $img;
    }
}
开发者ID:wildskyf,项目名称:www.moztw.org,代码行数:33,代码来源:eventpic.php

示例4: mysql_query_cache

function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    $mysqli = $GLOBALS['mysqli'];
    //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
    //如果返回false,此时就需要直接从数据库中获取数据了。
    //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
    //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
    //memcached处理时输出的相关信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = mysqli_query($mysqli, $sql);
        $fields = mysqli_fetch_fields($r);
        //读取数据库,并将结果放入$cache数组中
        for ($i = 0; $row = mysqli_fetch_array($r); $i++) {
            $j = 0;
            foreach ($fields as $val) {
                $cache[$i][$val->name] = $row[$j];
                $j++;
            }
        }
        //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
        //如果开启了服务器的话,数据将会被缓存到memcached服务器中
        if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
            # If we get here, there isn’t a memcache daemon running or responding
            echo "apt-get install memcached";
        }
    }
    return $cache;
}
开发者ID:RX78NY1,项目名称:hustoj,代码行数:29,代码来源:memcache.php

示例5: run

    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 1;
        $key = 'm/sharecate';
        $cache_list = getCache($key);
        if ($cache_list !== NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
            $cate_list = array();
            $min_time = $this->getQuarterMinTime();
            $max_time = getTodayTime();
            FanweService::instance()->cache->loadCache('albums');
            $album_cate = $_FANWE['cache']['albums']['category'];
            foreach ($album_cate as $k => $v) {
                $cate = array();
                $cate['cate_id'] = $v['id'];
                $cate['cate_name'] = $v['name'];
                $cate['short_name'] = $v['name'];
                $cate['cate_code'] = $v['cate_code'];
                $cate['cate_icon'] = FS("Image")->getImageUrl($v['img'], 2);
                $cate['desc'] = $v['desc'];
                $cate['create_time'] = $v['create_time'];
                //获取本季分享数量
                $share_count_sql = 'select count(DISTINCT s.share_id) from ' . FDB::table("share") . ' as s 
					INNER JOIN ' . FDB::table("album_share") . ' as al on s.share_id = al.share_id where al.cid = ' . $v['id'] . " and s.day_time >= {$min_time} AND s.day_time <= {$max_time} ";
                $cate['share_count'] = FDB::resultFirst($share_count_sql);
                $cate['img_tags'] = array();
                $img_size = 320;
                $sql = 'select s.share_id,al.title,sp.img from ' . FDB::table("share") . ' as s
					INNER JOIN ' . FDB::table("album_share") . ' as als ON s.share_id = als.share_id 
					INNER JOIN ' . FDB::table("album") . ' as al ON als.album_id = al.id
					INNER JOIN ' . FDB::table("share_photo") . " as sp ON s.share_id = sp.share_id \r\n\t\t\t\t\tWHERE s.day_time >= {$min_time} AND s.day_time <= {$max_time} AND als.cid = " . $v['id'] . " GROUP BY s.share_id ORDER BY s.share_id desc limit 5";
                $res = FDB::query($sql);
                while ($data = FDB::fetch($res)) {
                    $img_data = array();
                    $img_data['share_id'] = $data['share_id'];
                    $img_data['tag_name'] = $data['title'];
                    $img_data['is_tag'] = 0;
                    $img_data['img'] = FS("Image")->getImageUrl(getImgName($data['img'], $img_size, $img_size, 1, true), 2);
                    $img_data['url_tag'] = urlencode($data['title']);
                    $cate['img_tags'][] = $img_data;
                    $img_size = 160;
                }
                $cate['txt_tags'] = array();
                $cate_list[] = $cate;
            }
            $cache_list = array();
            $cache_list['cate_list'] = $cate_list;
            $cache_list['cache_time'] = TIME_UTC;
            setCache($key, $cache_list);
        } else {
            $cate_list = $cache_list['cate_list'];
        }
        $root['item'] = $cate_list;
        m_display($root);
    }
开发者ID:BGCX261,项目名称:zhubao-tupu-svn-to-git,代码行数:56,代码来源:sharecate.mapi.php

示例6: m_express

function m_express($content)
{
    global $_FANWE;
    $express = getCache('m_emotion_express_cache');
    //缓存过的表情hash
    if (!$express) {
        $express_rs = FDB::fetchAll("select `emotion`,concat('" . $_FANWE['site_url'] . "public/expression/',`type`,'/',`filename`) as fname from " . FDB::table('expression'));
        foreach ($express_rs as $k => $row) {
            $express[0][] = $row['emotion'];
            $express[1][] = "<img src='" . $row['fname'] . "' title='" . preg_replace("/[\\[\\]]/", '', $row['emotion']) . "' />";
        }
        setCache('m_emotion_express_cache', $express);
    }
    $content = str_replace($express[0], $express[1], $content);
    $parse_user = array();
    preg_match_all("/@([^\f\n\r\t\v@<> ]{2,20}?)(?:\\:| )/", $content, $users);
    if (!empty($users[1])) {
        $patterns = array();
        $replace = array();
        $users = array_unique($users[1]);
        $arr = array();
        foreach ($users as $user) {
            if (!empty($user)) {
                $arr[] = addslashes($user);
            }
        }
        $res = FDB::query('SELECT uid,user_name
			FROM ' . FDB::table('user') . '
			WHERE user_name ' . FDB::createIN($arr));
        while ($data = FDB::fetch($res)) {
            $parse_user[$data['user_name']] = $data['uid'];
        }
    }
    $parse_events = array();
    preg_match_all("/#([^\f\n\r\t\v]{1,80}?)#/", $content, $events);
    if (!empty($events[1])) {
        $patterns = array();
        $replace = array();
        $events = array_unique($events[1]);
        $arr = array();
        foreach ($events as $event) {
            if (!empty($event)) {
                $arr[] = addslashes($event);
            }
        }
        $res = FDB::query('SELECT id,title
			FROM ' . FDB::table('event') . '
			WHERE title ' . FDB::createIN($arr));
        while ($data = FDB::fetch($res)) {
            $parse_events[$data['title']] = $data['id'];
        }
    }
    return array("users" => $parse_user, "events" => $parse_events);
}
开发者ID:BGCX261,项目名称:zhubao-tupu-svn-to-git,代码行数:54,代码来源:base.mapi.php

示例7: getSiteByToken

 function getSiteByToken($token)
 {
     $cacheName = 'siteByToken' . $token;
     $cache = getCache($cacheName);
     if ($cache) {
         return unserialize($cache);
     } else {
         $site = $this->get_one(array('token' => $token));
         setCache($cacheName, serialize($site));
         return $site;
     }
 }
开发者ID:ailingsen,项目名称:pigcms,代码行数:12,代码来源:site_model.class.php

示例8: getContentPictures

 public function getContentPictures($id)
 {
     $id = intval($id);
     $crt = getCache('contentPictures' . $id);
     if ($crt) {
         return unserialize($crt);
     } else {
         $ps = $this->get_results('*', '', array('contentid' => $id), 'taxis ASC');
         setCache('contentPictures' . $id, serialize($ps));
         return $ps;
     }
 }
开发者ID:ailingsen,项目名称:pigcms,代码行数:12,代码来源:picture_model.class.php

示例9: keywords

 function keywords()
 {
     $cacheName = 'c_keywords';
     $cache = getCache($cacheName);
     if ($cache) {
         return unserialize($cache);
     } else {
         $keywords = $this->select();
         setCache($cacheName, serialize($keywords));
         return $keywords;
     }
 }
开发者ID:liuguogen,项目名称:weixin,代码行数:12,代码来源:keywords_model.class.php

示例10: getCompany

 public function getCompany($token)
 {
     $token = htmlspecialchars($token, ENT_QUOTES);
     $crt = getCache('company_' . $token);
     if (0 && $crt) {
         return unserialize($crt);
     } else {
         $ps = $this->get_one(array('token' => $token, 'isbranch' => 0));
         setCache('company_' . $token, serialize($ps));
         return $ps;
     }
 }
开发者ID:liuguogen,项目名称:weixin,代码行数:12,代码来源:company_model.class.php

示例11: giveCache

 /**
  * 生成缓存
  */
 protected function giveCache()
 {
     $model = D('Config');
     $wdata['status'] = 1;
     $list = $model->where($wdata)->select();
     foreach ($list as $array) {
         $data[$array['key']] = $array['val'];
         $data[$array['key']] = $array['val'];
     }
     //mk_dir(C('DATA_CACHE_PATH').'/config/');
     //F('list',$data,C('DATA_CACHE_PATH').'/config/');
     setCache('list', $data);
 }
开发者ID:8yong8,项目名称:vshop,代码行数:16,代码来源:ConfigController.class.php

示例12: navChannels

 public function navChannels($siteid)
 {
     $siteid = intval($siteid);
     $cacheName = 'navChannels' . $siteid;
     $cache = getCache($cacheName);
     if ($cache) {
         return unserialize($cache);
     } else {
         $channels = $this->select(array('site' => $siteid, 'isnav' => 1), '*', '', 'taxis ASC');
         setCache($cacheName, serialize($channels));
         return $channels;
     }
 }
开发者ID:liuguogen,项目名称:weixin,代码行数:13,代码来源:channel_model.class.php

示例13: GiveCache

 /**
  * 生成缓存
  */
 function GiveCache()
 {
     $model = D('Links');
     $wdata['status'] = 1;
     $list = $model->where($wdata)->select();
     /*
     if($list)F('list',$list,C('DATA_CACHE_PATH').'/links/');
     */
     if ($list) {
         setCache('list', $list);
     }
     if ($_GET['re']) {
         $this->success('更新完成!');
     }
 }
开发者ID:8yong8,项目名称:vshop,代码行数:18,代码来源:LinksController.class.php

示例14: extmail

  function extmail() {
   $req = new stdClass;
   $req->Get  = $_GET;
   $req->Post = $_POST;
   
//   ajax_echo_r ($req);
   
   $subject       = getvariablereq('subject');
   $mail_template = getvariablereq('mail_template');
   $email         = getvariablereq('email');
   $from_name     = getvariablereq('from_name');
   $from_mail     = getvariablereq('from_mail');
   
   $ret = sendmail ($subject, $mail_template, $email, $from_name, $from_mail);
   $req->Result = $ret;
   setCache('request-'.date('Y-m-d-H-i-s'), $req);
   echo json_encode($req);
  }
开发者ID:AragCF,项目名称:extmail2,代码行数:18,代码来源:Controller.php

示例15: run

 public function run()
 {
     global $_FANWE;
     $root = array();
     $root['return'] = 1;
     $uid = (int) $_FANWE['requestData']['uid'];
     $cid = (int) $_FANWE['requestData']['cid'];
     if ($uid > 0) {
         if (!FS('User')->getUserExists($uid)) {
             $uid = 0;
         }
     }
     if ($cid == 0) {
         $uid == 0;
     }
     if ($uid == 0) {
         $root['info'] = "请先登录";
         m_display($root);
     }
     $key = 'm/useralbum' . $uid . $cid;
     $album_list = getCache($key);
     if ($album_list !== NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
         $album_list = array();
         $sql = 'select id,title from ' . FDB::table('album') . " where cid = " . $cid . " and uid = " . $uid;
         $res = FDB::query($sql);
         $indx = 0;
         while ($data = FDB::fetch($res)) {
             $album_list[$indx] = $data;
             $indx++;
         }
         $cache_list = array();
         $cache_list['album_list'] = $album_list;
         $cache_list['cache_time'] = TIME_UTC;
         setCache($key, $cache_list);
     } else {
         $album_list = $cache_list['album_list'];
     }
     $root['item'] = $album_list;
     m_display($root);
 }
开发者ID:BGCX261,项目名称:zhubao-tupu-svn-to-git,代码行数:40,代码来源:useralbum.mapi.php


注:本文中的setCache函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。