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
0ed14a74
Commit
0ed14a74
authored
Mar 25, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished PageCache.
parent
de5c304f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
1 deletion
+112
-1
PageCache.php
framework/web/PageCache.php
+111
-0
FragmentCache.php
framework/widgets/FragmentCache.php
+1
-1
No files found.
framework/web/PageCache.php
0 → 100644
View file @
0ed14a74
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
use
Yii
;
use
yii\base\ActionFilter
;
use
yii\base\Action
;
use
yii\base\View
;
use
yii\caching\Dependency
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
PageCache
extends
ActionFilter
{
/**
* @var boolean whether the content being cached should be differentiated according to the route.
* A route consists of the requested controller ID and action ID. Defaults to true.
*/
public
$varyByRoute
=
true
;
/**
* @var View the view object that is used to create the fragment cache widget to implement page caching.
* If not set, the view registered with the application will be used.
*/
public
$view
;
/**
* @var string the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)
*/
public
$cacheID
=
'cache'
;
/**
* @var integer number of seconds that the data can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
*/
public
$duration
=
60
;
/**
* @var array|Dependency the dependency that the cached content depends on.
* This can be either a [[Dependency]] object or a configuration array for creating the dependency object.
* For example,
*
* ~~~
* array(
* 'class' => 'yii\caching\DbDependency',
* 'sql' => 'SELECT MAX(lastModified) FROM Post',
* )
* ~~~
*
* would make the output cache depends on the last modified time of all posts.
* If any post has its modification time changed, the cached content would be invalidated.
*/
public
$dependency
;
/**
* @var array list of factors that would cause the variation of the content being cached.
* Each factor is a string representing a variation (e.g. the language, a GET parameter).
* The following variation setting will cause the content to be cached in different versions
* according to the current application language:
*
* ~~~
* array(
* Yii::$app->language,
* )
*/
public
$variations
;
/**
* @var boolean whether to enable the fragment cache. You may use this property to turn on and off
* the fragment cache according to specific setting (e.g. enable fragment cache only for GET requests).
*/
public
$enabled
=
true
;
public
function
init
()
{
parent
::
init
();
if
(
$this
->
view
===
null
)
{
$this
->
view
=
Yii
::
$app
->
getView
();
}
}
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* You may override this method to do last-minute preparation for the action.
* @param Action $action the action to be executed.
* @return boolean whether the action should continue to be executed.
*/
public
function
beforeAction
(
$action
)
{
$properties
=
array
();
foreach
(
array
(
'cacheID'
,
'duration'
,
'dependency'
,
'variations'
,
'enabled'
)
as
$name
)
{
$properties
[
$name
]
=
$this
->
$name
;
}
$id
=
$this
->
varyByRoute
?
$action
->
getUniqueId
()
:
__CLASS__
;
return
$this
->
view
->
beginCache
(
$id
,
$properties
);
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param Action $action the action just executed.
*/
public
function
afterAction
(
$action
)
{
$this
->
view
->
endCache
();
}
}
\ No newline at end of file
framework/widgets/FragmentCache.php
View file @
0ed14a74
...
@@ -62,7 +62,7 @@ class FragmentCache extends Widget
...
@@ -62,7 +62,7 @@ class FragmentCache extends Widget
*/
*/
public
$enabled
=
true
;
public
$enabled
=
true
;
/**
/**
* @var \yii\base\View the view object within which this widget is
su
ed. If not set,
* @var \yii\base\View the view object within which this widget is
us
ed. If not set,
* the view registered with the application will be used. This is mainly used by dynamic content feature.
* the view registered with the application will be used. This is mainly used by dynamic content feature.
*/
*/
public
$view
;
public
$view
;
...
...
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