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
4a0d2863
Commit
4a0d2863
authored
Jun 12, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #421: yii\db\Schema:refresh() does not clear all cache
parent
00df1e88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
GroupDependency.php
framework/yii/caching/GroupDependency.php
+10
-7
Schema.php
framework/yii/db/Schema.php
+18
-5
No files found.
framework/yii/caching/GroupDependency.php
View file @
4a0d2863
...
...
@@ -42,11 +42,11 @@ class GroupDependency extends Dependency
*/
protected
function
generateDependencyData
(
$cache
)
{
if
(
$cache
->
get
(
array
(
__CLASS__
,
$this
->
group
))
===
false
)
{
// If the cutoff timestamp is not initialized or is swapped out of the cache, we need to set it.
$this
->
invalidate
(
$cache
,
array
(
__CLASS__
,
$this
->
group
));
$version
=
$cache
->
get
(
array
(
__CLASS__
,
$this
->
group
));
if
(
$version
===
false
)
{
$
version
=
$
this
->
invalidate
(
$cache
,
array
(
__CLASS__
,
$this
->
group
));
}
return
microtime
(
true
)
;
return
$version
;
}
/**
...
...
@@ -56,17 +56,20 @@ class GroupDependency extends Dependency
*/
public
function
getHasChanged
(
$cache
)
{
$
time
=
$cache
->
get
(
array
(
__CLASS__
,
$this
->
group
));
return
$
time
===
false
||
$time
>
$this
->
data
;
$
version
=
$cache
->
get
(
array
(
__CLASS__
,
$this
->
group
));
return
$
version
===
false
||
$version
!==
$this
->
data
;
}
/**
* Invalidates all of the cached data items that have the same [[group]].
* @param Cache $cache the cache component that caches the data items
* @param string $group the group name
* @return string the current version number
*/
public
static
function
invalidate
(
$cache
,
$group
)
{
$cache
->
set
(
array
(
__CLASS__
,
$group
),
microtime
(
true
));
$version
=
microtime
();
$cache
->
set
(
array
(
__CLASS__
,
$group
),
$version
);
return
$version
;
}
}
framework/yii/db/Schema.php
View file @
4a0d2863
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\NotSupportedException
;
use
yii\base\InvalidCallException
;
use
yii\caching\Cache
;
use
yii\caching\GroupDependency
;
/**
* Schema is the base class for concrete DBMS-specific schema classes.
...
...
@@ -93,7 +94,7 @@ abstract class Schema extends \yii\base\Object
if
(
$refresh
||
(
$table
=
$cache
->
get
(
$key
))
===
false
)
{
$table
=
$this
->
loadTableSchema
(
$realName
);
if
(
$table
!==
null
)
{
$cache
->
set
(
$key
,
$table
,
$db
->
schemaCacheDuration
);
$cache
->
set
(
$key
,
$table
,
$db
->
schemaCacheDuration
,
new
GroupDependency
(
$this
->
getCacheGroup
())
);
}
}
return
$this
->
_tables
[
$name
]
=
$table
;
...
...
@@ -107,7 +108,7 @@ abstract class Schema extends \yii\base\Object
* @param string $name the table name
* @return mixed the cache key
*/
p
ublic
function
getCacheKey
(
$name
)
p
rotected
function
getCacheKey
(
$name
)
{
return
array
(
__CLASS__
,
...
...
@@ -118,6 +119,20 @@ abstract class Schema extends \yii\base\Object
}
/**
* Returns the cache group name.
* This allows [[refresh()]] to invalidate all cached table schemas.
* @return string the cache group name
*/
protected
function
getCacheGroup
()
{
return
md5
(
serialize
(
array
(
__CLASS__
,
$this
->
db
->
dsn
,
$this
->
db
->
username
,
)));
}
/**
* Returns the metadata for all tables in the database.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name.
* @param boolean $refresh whether to fetch the latest available table schemas. If this is false,
...
...
@@ -176,9 +191,7 @@ abstract class Schema extends \yii\base\Object
/** @var $cache Cache */
$cache
=
is_string
(
$this
->
db
->
schemaCache
)
?
Yii
::
$app
->
getComponent
(
$this
->
db
->
schemaCache
)
:
$this
->
db
->
schemaCache
;
if
(
$this
->
db
->
enableSchemaCache
&&
$cache
instanceof
Cache
)
{
foreach
(
$this
->
_tables
as
$name
=>
$table
)
{
$cache
->
delete
(
$this
->
getCacheKey
(
$name
));
}
GroupDependency
::
invalidate
(
$cache
,
$this
->
getCacheGroup
());
}
$this
->
_tableNames
=
array
();
$this
->
_tables
=
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