本文整理汇总了PHP中wkcache函数的典型用法代码示例。如果您正苦于以下问题:PHP wkcache函数的具体用法?PHP wkcache怎么用?PHP wkcache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wkcache函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOwnShopIds
/**
* 获取自营店铺的ID
*
* @param boolean $bind_all_gc = false 是否只获取绑定全部类目的自营店 默认否(即全部自营店)
* @return array
*/
public function getOwnShopIds($bind_all_gc = false) {
$data = $this->ownShopIds;
// 属性为空则取缓存
if (!$data) {
$data = rkcache('own_shop_ids');
// 缓存为空则查库
if (!$data) {
$data = array();
$all_own_shops = $this->table('store')->field('store_id,bind_all_gc')->where(array(
'is_own_shop' => 1,
))->select();
foreach ((array) $all_own_shops as $v) {
$data[$v['store_id']] = (int) (bool) $v['bind_all_gc'];
}
// 写入缓存
wkcache('own_shop_ids', $data);
}
// 写入属性
$this->ownShopIds = $data;
}
return array_keys($bind_all_gc ? array_filter($data) : $data);
}
示例2: _get_wx_access_token
/**
* 获取微信access_token
*/
private function _get_wx_access_token()
{
// 尝试读取缓存的access_token
$access_token = rkcache('wx_access_token');
if ($access_token) {
$access_token = unserialize($access_token);
// 如果access_token未过期直接返回缓存的access_token
if ($access_token['time'] > TIMESTAMP) {
return $access_token['token'];
}
}
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';
$url = sprintf($url, $this->payment_config['wxpay_appid'], $this->payment_config['wxpay_appsecret']);
$re = http_get($url);
$result = json_decode($re, true);
if ($result['errcode']) {
return '';
}
// 缓存获取的access_token
$access_token = array();
$access_token['token'] = $result['access_token'];
$access_token['time'] = TIMESTAMP + $result['expires_in'];
wkcache('wx_access_token', serialize($access_token));
return $result['access_token'];
}
示例3: article
protected function article()
{
if (C('cache_open')) {
if ($article = rkcache("index/article")) {
Tpl::output('show_article', $article['show_article']);
Tpl::output('article_list', $article['article_list']);
return;
}
} else {
if (file_exists(BASE_DATA_PATH . '/cache/index/article.php')) {
include BASE_DATA_PATH . '/cache/index/article.php';
Tpl::output('show_article', $show_article);
Tpl::output('article_list', $article_list);
return;
}
}
$model_article_class = Model('article_class');
$model_article = Model('article');
$show_article = array();
//商城公告
$article_list = array();
//下方文章
$notice_class = array('notice');
$code_array = array('member', 'store', 'payment', 'sold', 'service', 'about');
$notice_limit = 5;
$faq_limit = 5;
$class_condition = array();
$class_condition['home_index'] = 'home_index';
$class_condition['order'] = 'ac_sort asc';
$article_class = $model_article_class->getClassList($class_condition);
$class_list = array();
if (!empty($article_class) && is_array($article_class)) {
foreach ($article_class as $key => $val) {
$ac_code = $val['ac_code'];
$ac_id = $val['ac_id'];
$val['list'] = array();
//文章
$class_list[$ac_id] = $val;
}
}
$condition = array();
$condition['article_show'] = '1';
$condition['home_index'] = 'home_index';
$condition['field'] = 'article.article_id,article.ac_id,article.article_url,article.article_title,article.article_time,article_class.ac_name,article_class.ac_parent_id';
$condition['order'] = 'article_sort asc,article_time desc';
$condition['limit'] = '300';
$article_array = $model_article->getJoinList($condition);
if (!empty($article_array) && is_array($article_array)) {
foreach ($article_array as $key => $val) {
$ac_id = $val['ac_id'];
$ac_parent_id = $val['ac_parent_id'];
if ($ac_parent_id == 0) {
//顶级分类
$class_list[$ac_id]['list'][] = $val;
} else {
$class_list[$ac_parent_id]['list'][] = $val;
}
}
}
if (!empty($class_list) && is_array($class_list)) {
foreach ($class_list as $key => $val) {
$ac_code = $val['ac_code'];
if (in_array($ac_code, $notice_class)) {
$list = $val['list'];
array_splice($list, $notice_limit);
$val['list'] = $list;
$show_article[$ac_code] = $val;
}
if (in_array($ac_code, $code_array)) {
$list = $val['list'];
$val['class']['ac_name'] = $val['ac_name'];
array_splice($list, $faq_limit);
$val['list'] = $list;
$article_list[] = $val;
}
}
}
if (C('cache_open')) {
wkcache('index/article', array('show_article' => $show_article, 'article_list' => $article_list));
} else {
$string = "<?php\n\$show_article=" . var_export($show_article, true) . ";\n";
$string .= "\$article_list=" . var_export($article_list, true) . ";\n?>";
file_put_contents(BASE_DATA_PATH . '/cache/index/article.php', $string);
}
Tpl::output('show_article', $show_article);
Tpl::output('article_list', $article_list);
}
示例4: getCachedData
/**
* 获取缓存
*
* @param string $key 缓存键
* @return array 缓存数据
*/
protected function getCachedData($key)
{
$data = $this->cachedData[$key];
// 属性中存在则返回
if ($data || is_array($data)) {
return $data;
}
$data = rkcache($key);
// 缓存中存在则返回
if ($data || is_array($data)) {
// 写入属性
$this->cachedData[$key] = $data;
return $data;
}
$data = $this->getCachingDataByQuery($key);
// 写入缓存
wkcache($key, $data);
// 写入属性
$this->cachedData[$key] = $data;
return $data;
}
示例5: rkcache
/**
* KV缓存 读
*
* @param string $key 缓存名称
* @param boolean $callback 缓存读取失败时是否使用回调 true代表使用cache.model中预定义的缓存项 默认不使用回调
* @param callable $callback 传递非boolean值时 通过is_callable进行判断 失败抛出异常 成功则将$key作为参数进行回调
* @return mixed
*/
function rkcache($key, $callback = false)
{
if (C('cache_open')) {
$cacher = Cache::getInstance('cacheredis');
} else {
$cacher = Cache::getInstance('file', null);
}
if (!$cacher) {
throw new Exception('Cannot fetch cache object!');
}
$value = $cacher->get($key);
if ($value === false && $callback !== false) {
if ($callback === true) {
$callback = array(Model('cache'), 'call');
}
if (!is_callable($callback)) {
throw new Exception('Invalid rkcache callback!');
}
$value = call_user_func($callback, $key);
wkcache($key, $value);
}
return $value;
}
示例6: get_all_category
/**
* 前台头部的商品分类
*
* @param number $update_all 更新
* @return array 数组
*/
public function get_all_category($update_all = 0)
{
// 不存在时更新或者强制更新时执行
if ($update_all == 1 || !($gc_list = rkcache('all_categories'))) {
$class_list = $this->getGoodsClassListAll();
$gc_list = array();
$class1_deep = array();
//第1级关联第3级数组
$class2_ids = array();
//第2级关联第1级ID数组
$type_ids = array();
//第2级分类关联类型
if (is_array($class_list) && !empty($class_list)) {
foreach ($class_list as $key => $value) {
$p_id = $value['gc_parent_id'];
//父级ID
$gc_id = $value['gc_id'];
$sort = $value['gc_sort'];
if ($p_id == 0) {
//第1级分类
$gc_list[$gc_id] = $value;
} elseif (array_key_exists($p_id, $gc_list)) {
//第2级
$class2_ids[$gc_id] = $p_id;
$type_ids[] = $value['type_id'];
$gc_list[$p_id]['class2'][$gc_id] = $value;
} elseif (array_key_exists($p_id, $class2_ids)) {
//第3级
$parent_id = $class2_ids[$p_id];
//取第1级ID
$gc_list[$parent_id]['class2'][$p_id]['class3'][$gc_id] = $value;
$class1_deep[$parent_id][$sort][] = $value;
}
}
$type_brands = $this->get_type_brands($type_ids);
//类型关联品牌
foreach ($gc_list as $key => $value) {
$gc_id = $value['gc_id'];
$pic_name = BASE_UPLOAD_PATH . '/' . ATTACH_COMMON . '/category-pic-' . $gc_id . '.jpg';
if (file_exists($pic_name)) {
$gc_list[$gc_id]['pic'] = UPLOAD_SITE_URL . '/' . ATTACH_COMMON . '/category-pic-' . $gc_id . '.jpg';
}
$class3s = $class1_deep[$gc_id];
if (is_array($class3s) && !empty($class3s)) {
//取关联的第3级
$class3_n = 0;
//已经找到的第3级分类个数
ksort($class3s);
//排序取到分类
foreach ($class3s as $k3 => $v3) {
if ($class3_n >= 5) {
//最多取5个
break;
}
foreach ($v3 as $k => $v) {
if ($class3_n >= 5) {
break;
}
if (is_array($v) && !empty($v)) {
$p_id = $v['gc_parent_id'];
$gc_id = $v['gc_id'];
$parent_id = $class2_ids[$p_id];
//取第1级ID
$gc_list[$parent_id]['class3'][$gc_id] = $v;
$class3_n += 1;
}
}
}
}
$class2s = $value['class2'];
if (is_array($class2s) && !empty($class2s)) {
//第2级关联品牌
foreach ($class2s as $k2 => $v2) {
$p_id = $v2['gc_parent_id'];
$gc_id = $v2['gc_id'];
$type_id = $v2['type_id'];
$gc_list[$p_id]['class2'][$gc_id]['brands'] = $type_brands[$type_id];
}
}
}
}
wkcache('all_categories', $gc_list);
}
return $gc_list;
}
示例7: makeApAllCache
/**
* 广告
*
* @return array
*/
public function makeApAllCache()
{
if (C('cache_open')) {
// *kcache() doesnt support iterating on keys
} else {
delCacheFile('adv');
}
$model = Model();
$ap_list = $model->table('adv_position')->where(array('is_use' => 1))->select();
$adv_list = $model->table('adv')->where(array('adv_end_date' => array('gt', time())))->order('slide_sort, adv_id desc')->select();
$array = array();
foreach ((array) $ap_list as $v) {
foreach ((array) $adv_list as $xv) {
if ($v['ap_id'] == $xv['ap_id']) {
$v['adv_list'][] = $xv;
}
}
// 写入缓存
$apId = (int) $v['ap_id'];
if (C('cache_open')) {
wkcache("adv/{$apId}", $v);
} else {
write_file(BASE_DATA_PATH . '/cache/adv/' . $apId . '.php', $v);
}
}
}
示例8: _getAllArea
private function _getAllArea()
{
$data = array();
$area_all_array = $this->limit(false)->select();
foreach ((array) $area_all_array as $a) {
$data['name'][$a['area_id']] = $a['area_name'];
$data['parent'][$a['area_id']] = $a['area_parent_id'];
$data['children'][$a['area_parent_id']][] = $a['area_id'];
if ($a['area_deep'] == 1 && $a['area_region']) {
$data['region'][$a['area_region']][] = $a['area_id'];
}
}
wkcache('area', $data);
$this->cachedData = $data;
return $data;
}
示例9: getCache
/**
* 获取地区数组 格式如下
* array(
* 'name' => array(
* '地区id' => '地区名称',
* // ..
* ),
* 'parent' => array(
* '子地区id' => '父地区id',
* // ..
* ),
* 'children' => array(
* '父地区id' => array(
* '子地区id 1',
* '子地区id 2',
* // ..
* ),
* // ..
* ),
* 'region' => array(array(
* '华北区' => array(
* '省级id 1',
* '省级id 2',
* // ..
* ),
* // ..
* ),
* )
*
* @return array
*/
protected function getCache()
{
// 对象属性中有数据则返回
if ($this->cachedData !== null) {
return $this->cachedData;
}
// 缓存中有数据则返回
if ($data = rkcache('area')) {
$this->cachedData = $data;
return $data;
}
// 查库
$data = array();
$area_all_array = $this->limit(false)->select();
foreach ((array) $area_all_array as $a) {
$data['name'][$a['area_id']] = $a['area_name'];
$data['parent'][$a['area_id']] = $a['area_parent_id'];
$data['children'][$a['area_parent_id']][] = $a['area_id'];
if ($a['area_deep'] == 1 && $a['area_region']) {
$data['region'][$a['area_region']][] = $a['area_id'];
}
}
wkcache('area', $data);
$this->cachedData = $data;
return $data;
}