### 文件
libraries/Yf/Cache.php 負責初始化并存放所有的Cache類。
~~~
調用方法
1.緩存頁面
$Cache = Yf_Cache::create('default');
$site_index_key = sprintf('%s|%s|%s', Yf_Registry::get('server_id'), 'site_index', isset($_COOKIE['sub_site_id']) ? $_COOKIE['sub_site_id'] : 0);
if (!$Cache->start($site_index_key))
{
//其他頁面代碼。。。
$Cache->_id = $site_index_key;
$Cache->end($site_index_key);
}
2.緩存數據
$cache_group = 'default';//配置信息中的緩存key
$Cache = Yf_Cache::create($cache_group);
$key = '';//緩存key
$data = '';//緩存數據
$Cache->save($data, $key);//保存緩存
$Cache->get($key,$cache_group);
底層實現
~~~
public $_cacheKeyPrefix = 'c|m|';
public $_cacheName = 'default';
public $_tableName = 'test';
public $_tablePrimaryKey = 'test_id';
public $_cacheFlag = false;
/**
* 取得
*
* @param array $id
*
* @return array $rows 信息
* @access protected
*/
protected function getCacheRow($id = null, &$need_cache_id_name)
{
fb($id);
$rows = array();
if (is_array($id)) {
if ($this->_cacheFlag) {
$Yf_Cache = Yf_Cache::create($this->_cacheName);
$cache_key = array();
$cache_key_index = array();
foreach ($id as $item) {
$cache_key[] = $this->_cacheKeyPrefix . $item;
$cache_key_index[$this->_cacheKeyPrefix . $item] = $item;
}
$rows_cache = array();
//fix file cache
$Yf_Registry = Yf_Registry::getInstance();
if (!isset($Yf_Registry['config_cache'][$this->_cacheName])) {
$this->_cacheName = 'default';
}
if (1 == $Yf_Registry['config_cache'][$this->_cacheName]['cacheType']) {
foreach ($cache_key as $key_id) {
$tmp_data = $Yf_Cache->get($key_id);
if (false === $tmp_data) {
} else {
$rows_cache[$key_id] = $tmp_data;
}
}
//end fix file cache
} else {
$rows_cache = $Yf_Cache->get($cache_key);
}
foreach ($cache_key as $val) {
if (!isset($rows_cache[$val])) {
array_push($need_cache_id_name, $cache_key_index[$val]);
} else {
$rows = $rows + (array)$rows_cache[$val];
}
}
}
}
//fb($rows, "getCacheRow(" . encode_json($id) . ", " . encode_json($need_cache_id_name) . ")");
return $rows;
}
/**
* 添加緩存,為多條記錄
*
* @param array $rows_db
*
* @return array $rows 信息
* @access protected
*/
protected function setCacheRow($rows_db = null, $expire = null)
{
if ($this->_cacheFlag) {
if (false !== $rows_db) {
$Yf_Cache = Yf_Cache::create($this->_cacheName);
foreach ($rows_db as $key => $val) {
//fix file cache
$Yf_Registry = Yf_Registry::getInstance();
if (!isset($Yf_Registry['config_cache'][$this->_cacheName])) {
$this->_cacheName = 'default';
}
if (1 == $Yf_Registry['config_cache'][$this->_cacheName]['cacheType']) {
$Yf_Cache->save(array($key => $val), $this->_cacheKeyPrefix . $key);
} else {
$Yf_Cache->save(array($key => $val), $this->_cacheKeyPrefix . $key, null, 0, $expire);
}
//end fix file cache
/*
$Yf_Cache->save(array($key=>$val), $this->_cacheKeyPrefix . $key, null, 0, $expire);
//$this->setCache(array($key=>$val), $this->_cacheKeyPrefix . $key);
*/
}
}
}
}
/**
* 取得單個緩存
*
* @param int $id id
*
* @return array $rows 信息
* @access protected
*/
protected function getCache($id = null)
{
$rows = array();
if ($this->_cacheFlag) {
$Yf_Cache = Yf_Cache::create($this->_cacheName);
if ($id) {
if (is_array($id)) {
$cache_key = array();
foreach ($id as $k => $v) {
$cache_key[] = $this->_cacheKeyPrefix . $v;
}
} else {
$cache_key = $this->_cacheKeyPrefix . $id;
}
} else {
$cache_key = $this->_cacheKeyPrefix . 'all';
}
$rows = $Yf_Cache->get($cache_key);
}
fb($cache_key, 'getCache');
fb($rows);
return $rows;
}
/**
* 添加緩存,為單條記錄
*
* @param array $rows_db
*
* @return array $rows 信息
* @access protected
*/
protected function setCache($rows_db, $key = null, $expire = null)
{
if ($this->_cacheFlag) {
if (false !== $rows_db) {
$Yf_Cache = Yf_Cache::create($this->_cacheName);
//fix file cache
$Yf_Registry = Yf_Registry::getInstance();
if (!isset($Yf_Registry['config_cache'][$this->_cacheName])) {
$this->_cacheName = 'default';
}
if (1 == $Yf_Registry['config_cache'][$this->_cacheName]['cacheType']) {
if ($key) {
return $Yf_Cache->save($rows_db, $this->_cacheKeyPrefix . $key);
} else {
return $Yf_Cache->save($rows_db, null);
}
} else {
if ($key) {
return $Yf_Cache->save($rows_db, $this->_cacheKeyPrefix . $key, null, 0, $expire);
} else {
return $Yf_Cache->save($rows_db, null, null, 0, $expire);
}
}
//end fix file cache
}
}
}
~~~
- 序言
- 系統要求
- 版本更新日志
- 遠豐商城技術對接說明
- 開發指導
- 系統架構
- 負載集群
- 云存儲
- 框架內容
- 基礎
- 開發規范
- 目錄結構
- 架構
- 架構總覽
- 數據庫
- 數據庫連接
- 基本使用
- 緩存
- 配置
- 路由
- 數據字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- shop1
- shop2
- shop3
- 通訊內容
- 商家中心
- 頂部導航欄
- 店鋪信息欄
- 店鋪及商品提示欄
- 交易提示欄
- 銷售情況統計欄
- 集群架構圖
- 單品銷量排行欄
- 店鋪運營推廣欄
- 平臺聯系方式欄
- 訂單物流
- 商品
- 商品列表
- 商品詳情
- 商品發布與編輯
- 分銷商品
- 關聯版式
- 商品規格
- 圖片空間
- 淘寶導入
- 訂單流程
- 交易訂單
- 訂單退款/退貨
- 促銷
- 團購管理
- 加價購
- 限時折扣
- 滿即送
- 代金券管理
- 分銷
- 店鋪
- 店鋪設置
- 自銷產品供應商
- 實體店鋪
- 品牌申請
- 店鋪信息
- 消費者保障服務
- 門店賬號
- 分銷商--產品供應商
- 分銷明細
- 批發市場
- 商家微信公眾號
- 售后服務
- 咨詢管理
- 投訴管理
- 退款管理
- 退貨管理
- 雜項
- 遠程上傳圖片
- 接口(廢棄,參考最外層接口項)
- 接口說明
- 品牌
- 商品規格
- 商品類型
- 商品分類
- 商品
- 訂單
- 商品/店鋪收藏
- 足跡
- 退款及退貨
- 商家店鋪
- 會員
- 入駐協議
- 訂單接口
- 商品接口
- 訂單物流接口
- 商家中心接口
- 促銷接口
- 快遞鳥物流接口
- 代金券接口
- 首頁版塊
- 團購
- 平臺紅包
- 限時折扣接口
- 拼團接口
- wap首頁模板
- JS
- 銀聯支付
- 多語言
- 商品評分
- 圖片加載
- 買家申請退款退貨
- 商家退款退貨
- 平臺退款退貨
- 添加發票
- 提交訂單
- 確認訂單
- 運費銷售區域
- 獲取會員地址
- 充值
- 導出XLS
- 商城系統集成
- 多語言實現
- 三級分銷推廣鏈接發展推廣員
- app.ini.php
- 去分銷
- 版本更新
- 物流支持
- 運營人員建議
- 業務邏輯
- 統計結算
- 客服消息
- 賬號
- 三級分銷
- IM
- 配置
- 平臺帳號
- 活動數據表說明
- 接口
- 數據庫中間鍵
- MyCat的優勢
- 概念說明
- Mycat的下載及安裝
- 參數配置案列
- Mycat讀寫分離
- 基本命令
- 常見錯誤