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
4674f5b7
Commit
4674f5b7
authored
Apr 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #3052: Fixed the issue that cache dependency data is not reused when `reusable` is set true
parent
3349af1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
23 deletions
+30
-23
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Dependency.php
framework/caching/Dependency.php
+29
-23
No files found.
framework/CHANGELOG.md
View file @
4674f5b7
...
@@ -64,6 +64,7 @@ Yii Framework 2 Change Log
...
@@ -64,6 +64,7 @@ Yii Framework 2 Change Log
-
Bug #2834: When overriding i18n translation sources from config using
`app*`
or
`yii*`
default
`app`
and
`yii`
sources were not removed (samdark)
-
Bug #2834: When overriding i18n translation sources from config using
`app*`
or
`yii*`
default
`app`
and
`yii`
sources were not removed (samdark)
-
Bug #2848: Individual queries should be enclosed within parenthesis in a UNION query (qiangxue)
-
Bug #2848: Individual queries should be enclosed within parenthesis in a UNION query (qiangxue)
-
Bug #2862: Using
`DbCache`
while enabling schema caching may cause infinite loops (qiangxue)
-
Bug #2862: Using
`DbCache`
while enabling schema caching may cause infinite loops (qiangxue)
-
Bug #3052: Fixed the issue that cache dependency data is not reused when
`reusable`
is set true (qiangxue)
-
Bug: Fixed
`Call to a member function registerAssetFiles() on a non-object`
in case of wrong
`sourcePath`
for an asset bundle (samdark)
-
Bug: Fixed
`Call to a member function registerAssetFiles() on a non-object`
in case of wrong
`sourcePath`
for an asset bundle (samdark)
-
Bug: Fixed incorrect event name for
`yii\jui\Spinner`
(samdark)
-
Bug: Fixed incorrect event name for
`yii\jui\Spinner`
(samdark)
-
Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
-
Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
...
...
framework/caching/Dependency.php
View file @
4674f5b7
...
@@ -35,10 +35,6 @@ abstract class Dependency extends \yii\base\Object
...
@@ -35,10 +35,6 @@ abstract class Dependency extends \yii\base\Object
* @var array static storage of cached data for reusable dependencies.
* @var array static storage of cached data for reusable dependencies.
*/
*/
private
static
$_reusableData
=
[];
private
static
$_reusableData
=
[];
/**
* @var string a unique hash value for this cache dependency.
*/
private
$_hash
;
/**
/**
* Evaluates the dependency by generating and saving the data related with dependency.
* Evaluates the dependency by generating and saving the data related with dependency.
...
@@ -47,16 +43,14 @@ abstract class Dependency extends \yii\base\Object
...
@@ -47,16 +43,14 @@ abstract class Dependency extends \yii\base\Object
*/
*/
public
function
evaluateDependency
(
$cache
)
public
function
evaluateDependency
(
$cache
)
{
{
if
(
!
$this
->
reusable
)
{
if
(
$this
->
reusable
)
{
$this
->
data
=
$this
->
generateDependencyData
(
$cache
);
$hash
=
$this
->
generateReusableHash
();
}
else
{
if
(
!
array_key_exists
(
$hash
,
self
::
$_reusableData
))
{
if
(
$this
->
_hash
===
null
)
{
self
::
$_reusableData
[
$hash
]
=
$this
->
generateDependencyData
(
$cache
);
$this
->
_hash
=
sha1
(
serialize
(
$this
));
}
}
if
(
!
array_key_exists
(
$this
->
_hash
,
self
::
$_reusableData
))
{
$this
->
data
=
self
::
$_reusableData
[
$hash
];
self
::
$_reusableData
[
$this
->
_hash
]
=
$this
->
generateDependencyData
(
$cache
);
}
else
{
}
$this
->
data
=
$this
->
generateDependencyData
(
$cache
);
$this
->
data
=
self
::
$_reusableData
[
$this
->
_hash
];
}
}
}
}
...
@@ -67,18 +61,16 @@ abstract class Dependency extends \yii\base\Object
...
@@ -67,18 +61,16 @@ abstract class Dependency extends \yii\base\Object
*/
*/
public
function
getHasChanged
(
$cache
)
public
function
getHasChanged
(
$cache
)
{
{
if
(
!
$this
->
reusable
)
{
if
(
$this
->
reusable
)
{
return
$this
->
generateDependencyData
(
$cache
)
!==
$this
->
data
;
$hash
=
$this
->
generateReusableHash
();
}
else
{
if
(
!
array_key_exists
(
$hash
,
self
::
$_reusableData
))
{
if
(
$this
->
_hash
===
null
)
{
self
::
$_reusableData
[
$hash
]
=
$this
->
generateDependencyData
(
$cache
);
$this
->
_hash
=
sha1
(
serialize
(
$this
));
}
}
if
(
!
array_key_exists
(
$this
->
_hash
,
self
::
$_reusableData
))
{
$data
=
self
::
$_reusableData
[
$hash
];
self
::
$_reusableData
[
$this
->
_hash
]
=
$this
->
generateDependencyData
(
$cache
);
}
else
{
}
$data
=
$this
->
generateDependencyData
(
$cache
);
return
self
::
$_reusableData
[
$this
->
_hash
]
!==
$this
->
data
;
}
}
return
$data
!==
$this
->
data
;
}
}
/**
/**
...
@@ -90,6 +82,20 @@ abstract class Dependency extends \yii\base\Object
...
@@ -90,6 +82,20 @@ abstract class Dependency extends \yii\base\Object
}
}
/**
/**
* Generates a unique hash that can be used for retrieving reusable dependency data.
* @return string a unique hash value for this cache dependency.
* @see reusable
*/
protected
function
generateReusableHash
()
{
$data
=
$this
->
data
;
$this
->
data
=
null
;
// https://github.com/yiisoft/yii2/issues/3052
$key
=
sha1
(
serialize
(
$this
));
$this
->
data
=
$data
;
return
$key
;
}
/**
* Generates the data needed to determine if dependency has been changed.
* Generates the data needed to determine if dependency has been changed.
* Derived classes should override this method to generate the actual dependency data.
* Derived classes should override this method to generate the actual dependency data.
* @param Cache $cache the cache component that is currently evaluating this dependency
* @param Cache $cache the cache component that is currently evaluating this dependency
...
...
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