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
ebcc936a
Commit
ebcc936a
authored
May 22, 2013
by
resurtm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #145. Reusable cache dependencies.
parent
a954312a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
2 deletions
+46
-2
Dependency.php
framework/yii/caching/Dependency.php
+46
-2
No files found.
framework/yii/caching/Dependency.php
View file @
ebcc936a
...
...
@@ -25,6 +25,22 @@ abstract class Dependency extends \yii\base\Object
* latest dependency data.
*/
public
$data
;
/**
* @var boolean whether this dependency is reusable or not. True value means that dependent
* data for this cache dependency will only be generated once per request. This allows you
* to use the same cache dependency for multiple separate cache calls while generating the same
* page without an overhead of re-evaluating dependency data each time. Defaults to false.
*/
public
$reuseData
=
false
;
/**
* @var array static storage of cached data for reusable dependencies.
*/
private
static
$_reusableData
=
array
();
/**
* @var string a unique hash value for this cache dependency.
*/
private
$_hash
;
/**
* Evaluates the dependency by generating and saving the data related with dependency.
...
...
@@ -32,7 +48,17 @@ abstract class Dependency extends \yii\base\Object
*/
public
function
evaluateDependency
()
{
$this
->
data
=
$this
->
generateDependencyData
();
if
(
!
$this
->
reuseData
)
{
$this
->
data
=
$this
->
generateDependencyData
();
}
else
{
if
(
$this
->
_hash
===
null
)
{
$this
->
_hash
=
sha1
(
serialize
(
$this
));
}
if
(
!
array_key_exists
(
$this
->
_hash
,
self
::
$_reusableData
))
{
self
::
$_reusableData
[
$this
->
_hash
]
=
$this
->
generateDependencyData
();
}
$this
->
data
=
self
::
$_reusableData
[
$this
->
_hash
];
}
}
/**
...
...
@@ -40,7 +66,25 @@ abstract class Dependency extends \yii\base\Object
*/
public
function
getHasChanged
()
{
return
$this
->
generateDependencyData
()
!==
$this
->
data
;
if
(
!
$this
->
reuseData
)
{
return
$this
->
generateDependencyData
()
!==
$this
->
data
;
}
else
{
if
(
$this
->
_hash
===
null
)
{
$this
->
_hash
=
sha1
(
serialize
(
$this
));
}
if
(
!
array_key_exists
(
$this
->
_hash
,
self
::
$_reusableData
))
{
self
::
$_reusableData
[
$this
->
_hash
]
=
$this
->
generateDependencyData
();
}
return
self
::
$_reusableData
[
$this
->
_hash
]
!==
$this
->
_data
;
}
}
/**
* Resets all cached data for reusable dependencies.
*/
public
static
function
resetReusableData
()
{
self
::
$_reusableData
=
array
();
}
/**
...
...
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