本文整理匯總了PHP中Q::writeCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP Q::writeCache方法的具體用法?PHP Q::writeCache怎麽用?PHP Q::writeCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Q
的用法示例。
在下文中一共展示了Q::writeCache方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: render
function render()
{
//得到屬性的值
$name = $this->_extract('name');
$catch_id = 'Dy_menu' . $name;
//讀取緩存
$rowSet = Q::cache($catch_id);
//讀取失敗
if (!$rowSet) {
$rowSet = Sysmenu::find()->order('parent_id ASC, order_pos ASC')->asArray()->getAll();
//寫緩存
Q::writeCache($catch_id, $rowSet);
}
/**
* 驗證不能訪問的菜單
*/
$app = MyApp::instance();
foreach ($rowSet as $offset => $row) {
if ($row['controller'] == '') {
continue;
}
$udi = "{$row['controller']}/{$row['action']}";
//權限判斷
if (!$app->authorizedUDI($app->currentUserRoles(), $udi)) {
//刪除沒有權限訪問的菜單
unset($rowSet[$offset]);
} else {
$args = array();
parse_str($row['args'], $args);
$rowSet[$offset]['url'] = url($udi, $args);
}
}
//數組轉換成樹
$menu = Helper_Array::toTree($rowSet, 'menu_id', 'parent_id', 'submenu');
// $mainMenu = & new Helper_Menu($menu) ;
$mainMenu = new Helper_Menu($menu);
$output = "var {$name} = ";
$output .= $mainMenu->returnJsArray(true);
$output .= ";\n";
echo <<<EOT
<div id="mainMenuBar"></div>
<link href="js/ThemeOffice/theme.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/JSCookMenu.js"></script>
<script language="javascript" type="text/javascript" src="js/ThemeOffice/theme.js"></script>
<script language="javascript" type="text/javascript">
{{$output}}
cmDraw ('mainMenuBar', myMenu, 'hbr', cmThemeOffice);
</script>
EOT;
}
示例2: testCache
/**
* 測試緩存的讀寫
*
* 使用 QCache_Memory
*/
function testCache()
{
$backend = 'QCache_Memory';
$id = 'test_cache_id1';
$data = Q::cache($id, null, $backend);
$this->assertEmpty($data);
$data = array('value');
Q::writeCache($id, $data, null, $backend);
$data2 = Q::cache($id, null, $backend);
$this->assertEquals($data, $data2);
Q::cleanCache($id, null, $backend);
$data2 = Q::cache($id, null, $backend);
$this->assertEmpty($data2);
}
示例3: import
/**
* 導入路由規則
*
* 如果指定了 $cache_id 參數,則首先嘗試從緩存載入解析好的路由規則。
*
* @param array $rules
* @param string $cache_id
*
* @return QRouter
*/
function import(array $rules, $cache_id = null)
{
if ($cache_id) {
$backend = Q::ini('runtime_cache_backend');
$routes = Q::cache($cache_id, null, $backend);
}
if (!$cache_id || !$routes) {
$routes = array();
foreach ($rules as $route_name => $rule) {
$routes[$route_name] = $this->prepareRoute($route_name, $rule);
}
if ($cache_id) {
Q::writeCache($cache_id, $routes, array('life_time' => Q::ini('routes_cache_lifetime')), $backend);
}
}
$this->_routes = array_merge($this->_routes, $routes);
return $this;
}
示例4: _setupMeta
/**
* 設置當前數據表的元數據
*/
protected function _setupMeta()
{
$table_name = $this->getFullTableName();
$this->_cache_id = $this->_conn->getID() . '-' . $table_name;
if (isset(self::$_meta[$this->_cache_id])) {
return;
}
$cached = Q::ini('db_meta_cached');
if ($cached) {
// 嘗試從緩存讀取
$policy = array('encoding_filename' => true, 'serialize' => true, 'life_time' => Q::ini('db_meta_lifetime'), 'cache_dir' => Q::ini('runtime_cache_dir'));
$backend = Q::ini('db_meta_cache_backend');
$data = Q::cache($this->_cache_id, $policy, $backend);
if (is_array($data) && !empty($data)) {
self::$_meta[$this->_cache_id] = $data[0];
self::$_fields[$this->_cache_id] = $data[1];
return;
}
}
// 從數據庫獲得 meta
$meta = $this->_conn->metaColumns($table_name);
$fields = array();
foreach ($meta as $field) {
$fields[$field['name']] = true;
}
self::$_meta[$this->_cache_id] = $meta;
self::$_fields[$this->_cache_id] = $fields;
$data = array($meta, $fields);
if ($cached) {
// 緩存數據
Q::writeCache($this->_cache_id, $data, $policy, $backend);
}
}