本文整理汇总了PHP中Q::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::cache方法的具体用法?PHP Q::cache怎么用?PHP Q::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q
的用法示例。
在下文中一共展示了Q::cache方法的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);
}
}