本文整理汇总了PHP中setCache函数的典型用法代码示例。如果您正苦于以下问题:PHP setCache函数的具体用法?PHP setCache怎么用?PHP setCache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setCache函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: mysql_query_cache
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 60)
{
if (($cache = getCache(md5("mysql_query" . $sql))) !== false) {
$cache = false;
$r = $linkIdentifier !== false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql);
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];
}
}
if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
# Error en Memcache
}
}
}
return $cache;
}
开发者ID:asbag,项目名称:memcached,代码行数:23,代码来源:singleserver.php
示例17: getBlockedUserIDs
function getBlockedUserIDs($receive = 0, $send = 0)
{
global $plugins;
global $userid;
global $blockpluginmode;
$blockedIds = array();
$querystring = "";
if ($send == 1) {
$querystring = "select fromid as blockedid from cometchat_block where toid = '" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "' UNION ";
}
if (in_array('block', $plugins)) {
if ($receive == 0) {
if (!is_array($blockedIds = getCache('blocked_id_of_' . $userid))) {
$blockedIds = array();
$sql = "select group_concat(blockedid) blockedids from (" . $querystring . " select toid as blockedid from cometchat_block where fromid = '" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "') as blocked";
$query = mysqli_query($GLOBALS['dbh'], $sql);
$blockedId = mysqli_fetch_assoc($query);
if (!empty($blockedId['blockedids'])) {
$blockedIds = explode(',', $blockedId['blockedids']);
}
setCache('blocked_id_of_' . $userid, $blockedIds, 3600);
}
} else {
if (!is_array($blockedIds = getCache('blocked_id_of_receive_' . $userid)) && $receive == 1) {
$blockedIds = array();
$sql = "select group_concat(toid) blockedids from cometchat_block where fromid = '" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "'";
$query = mysqli_query($GLOBALS['dbh'], $sql);
$blockedId = mysqli_fetch_assoc($query);
if (!empty($blockedId['blockedids'])) {
$blockedIds = explode(',', $blockedId['blockedids']);
}
setCache('blocked_id_of_receive_' . $userid, $blockedIds, 3600);
}
}
}
return $blockedIds;
}
开发者ID:albertoneto,项目名称:localhost,代码行数:37,代码来源:cometchat_shared.php
示例18: clearCache
public function clearCache() {
$this->cache = array(); // init cache
setCache('data',$this->cache); // clear disk cache
}
开发者ID:serega011,项目名称:izumrud,代码行数:4,代码来源:Model.php
示例19: GiveCache
/**
* 生成缓存
*/
function GiveCache()
{
$name = CONTROLLER_NAME;
$model = M($name);
$wdata['status'] = 1;
//$wdata['pay_class'] = 'ali';
$list = $model->where($wdata)->order('id desc')->select();
foreach ($list as $val) {
/*
if($val['pay_class']=='ali'){
$this->alipay_cache($val);
}else if($val['pay_class']=='wx'){
$this->wxpay_cache($val);
}else if($val['pay_class']=='wxapp'){
$this->wxapppay_cache($val);
}
*/
$key = $val['pay_class'];
$list2[$key] = $val;
}
//F('pay',$list2,C('DATA_CACHE_PATH').'/config/');
setCache('Config:pay', $list2);
}
开发者ID:8yong8,项目名称:vshop,代码行数:26,代码来源:PaymentConfigController.class.php
示例20: run
//.........这里部分代码省略.........
ajax_echo($tmp->output());
break;
case ("showgallery"):
// ajax_echo_r($json);
if ($json->operation=='download') {
$ret = $this->model->getGalleryItem($json);
} else {
if ($json->operation=='delete') {
$ret = $this->model->deleteGalleryItem($json);
}
$gal = $this->getGallery($json);
$ret = $gal->compiled;
}
ajax_echo ($ret);
break;
case ('postevent'):
$ret=$this->model->addEvent($json);
// ajax_echo_r ($ret->rowsAffected);
ajax_echo_r($json);
break;
case ('getnewevents'):
$events = $this->model->getNewEvents($json);
echo json_encode($events);
break;
case ('processxls'):
$xls = $this->model->loadXls(0);
setCache('settings',$json);
if ($xls) {
$data = $this->model->processXls($xls, $json);
} else {
$data = "";
}
ajax_echo_r($data);
break;
case ('showtable'):
$json->tablename = $json->go;
$thisdebug = 0;
if ($thisdebug) $mtime = microtime(true);
switch ($json->go) {
case ('news'):
$params = new stdClass;
$params->listid=-1;
$table = $this->model->getTasks($params);
break;
case ('users'):
if ($userdetails->GroupID!=1) $id = $userdetails->ID;
$table[1] = $this->model->getUsers($json, $id);
break;
case ('dashboard'):
// see case sections for each dashboard subpage
break;
case ('objects'):
$table = $this->model->getObjects($json);
break;
case ('customers'):
开发者ID:serega011,项目名称:izumrud,代码行数:67,代码来源:Controller.php
注:本文中的setCache函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论