Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
82d92ccd
Commit
82d92ccd
authored
Jul 17, 2014
by
AbrahamGreyson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Caching-page.md translated. [skip ci]
parent
1a7aedab
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
caching-page.md
docs/guide-zh-CN/caching-page.md
+40
-0
No files found.
docs/guide-zh-CN/caching-page.md
0 → 100644
View file @
82d92ccd
页面缓存
============
页面缓存指的是在服务器端缓存整个页面的内容。随后当同一个页面被请求时,内容将从缓存中取出,而不是重新生成。
页面缓存由
[
[yii\filters\PageCache
]
] 类提供支持,该类是一个
[
过滤器
](
structure-filters.md
)
。它可以像这样在控制器类中使用:
```
php
public
function
behaviors
()
{
return
[
[
'class'
=>
'yii\filters\PageCache'
,
'only'
=>
[
'index'
],
'duration'
=>
60
,
'variations'
=>
[
\Yii
::
$app
->
language
,
],
'dependency'
=>
[
'class'
=>
'yii\caching\DbDependency'
,
'sql'
=>
'SELECT COUNT(*) FROM post'
,
],
],
];
}
```
上述代码表示页面缓存只在
`index`
操作时启用,页面内容最多被缓存 60 秒,会随着当前应用的语言更改而变化。如果文章总数发生变化则缓存的页面会失效。
如你所见,页面缓存和
[
片段缓存
](
caching-fragment.md
)
极其相似。它们都支持
`duration`
,
`dependencies`
,
`variations`
和
`enabled`
配置选项。它们的主要区别是页面缓存是由
[
过滤器
](
structure-filters.md
)
实现,而片段缓存则是一个
[
小部件
](
structure-widgets.md
)
。
你可以在使用页面缓存的同时,使用
[
片段缓存
](
caching-fragment.md
)
和
[
动态内容
](
caching-fragment.md#dynamic-content
)
。
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment