當前位置: 首頁>>代碼示例>>PHP>>正文


PHP wkcache函數代碼示例

本文整理匯總了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);
    }
開發者ID:noikiy,項目名稱:ejia,代碼行數:34,代碼來源:store.model.php

示例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'];
 }
開發者ID:noikiy,項目名稱:meizhan,代碼行數:28,代碼來源:member_payment.php

示例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);
 }
開發者ID:uwitec,項目名稱:xbshop,代碼行數:87,代碼來源:control.php

示例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;
 }
開發者ID:flying3615,項目名稱:chuniang,代碼行數:27,代碼來源:groupbuy.model.php

示例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;
}
開發者ID:flying3615,項目名稱:chuniang,代碼行數:31,代碼來源:core.php

示例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;
 }
開發者ID:ff00x0,項目名稱:shopnc,代碼行數:91,代碼來源:goods_class.model.php

示例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);
         }
     }
 }
開發者ID:noikiy,項目名稱:shopnc-minion,代碼行數:31,代碼來源:adv.model.php

示例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;
 }
開發者ID:1290800466,項目名稱:mac_win,代碼行數:16,代碼來源:area.model.php

示例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;
 }
開發者ID:uwitec,項目名稱:xbshop,代碼行數:57,代碼來源:area.model.php


注:本文中的wkcache函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。