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
9d75714b
Commit
9d75714b
authored
Jan 05, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored query caching and schema caching.
parent
8517ee9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
49 deletions
+54
-49
Command.php
framework/db/Command.php
+2
-3
Connection.php
framework/db/Connection.php
+52
-46
No files found.
framework/db/Command.php
View file @
9d75714b
...
...
@@ -365,13 +365,12 @@ class Command extends \yii\base\Component
}
\Yii
::
trace
(
"Querying SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
echo
$sql
.
"
\n\n
"
;
if
(
$db
->
queryCachingCount
>
0
&&
$db
->
queryCachingDuration
>=
0
&&
$method
!==
''
)
{
if
(
$db
->
enableQueryCache
&&
$method
!==
''
)
{
$cache
=
\Yii
::
$application
->
getComponent
(
$db
->
queryCacheID
);
}
if
(
isset
(
$cache
))
{
$db
->
queryCachingCount
--
;
$cacheKey
=
__CLASS__
.
"/
{
$db
->
dsn
}
/
{
$db
->
username
}
/
$sql
/
$paramLog
"
;
if
((
$result
=
$cache
->
get
(
$cacheKey
))
!==
false
)
{
\Yii
::
trace
(
'Query result found in cache'
,
__CLASS__
);
...
...
framework/db/Connection.php
View file @
9d75714b
...
...
@@ -130,62 +130,63 @@ class Connection extends \yii\base\ApplicationComponent
*/
public
$pdo
;
/**
* @var boolean whether to enable schema caching.
* Note that in order to enable truly schema caching, a valid cache component as specified
* by [[schemaCacheID]] must be enabled and [[schemaCacheEnabled]] must be set true.
* @see schemaCacheDuration
* @see schemaCacheExclude
* @see schemaCacheID
*/
public
$enableSchemaCache
=
false
;
/**
* @var integer number of seconds that table metadata can remain valid in cache.
* Defaults to -1, meaning schema caching is disabled.
* Use 0 to indicate that the cached data will never expire.
*
* Note that in order to enable schema caching, a valid cache component as specified
* by [[schemaCacheID]] must be enabled.
* @see schemaCachingExclude
* @see schemaCacheID
* @see enableSchemaCache
*/
public
$schemaCach
ingDuration
=
-
1
;
public
$schemaCach
eDuration
=
3600
;
/**
* @var array list of tables whose metadata should NOT be cached. Defaults to empty array.
* The table names may contain schema prefix, if any. Do not quote the table names.
* @see
schemaCachingDuration
* @see
enableSchemaCache
*/
public
$schemaCach
ing
Exclude
=
array
();
public
$schemaCach
e
Exclude
=
array
();
/**
* @var string the ID of the cache application component that is used to cache the table metadata.
* Defaults to 'cache'.
* @see
schemaCachingDuration
* @see
enableSchemaCache
*/
public
$schemaCacheID
=
'cache'
;
/**
* @var integer number of seconds that query results can remain valid in cache.
* Defaults to -1, meaning query caching is disabled.
* Use 0 to indicate that the cached data will never expire.
*
* @var boolean whether to enable query caching.
* Note that in order to enable query caching, a valid cache component as specified
* by [[queryCacheID]] must be enabled.
*
* The method [[cache()]] is provided as a convenient way of setting this property
* and [[queryCachingDependency]] on the fly.
* by [[queryCacheID]] must be enabled and [[queryCacheEnabled]] must be set true.
*
* @see cache
* @see queryCachingDependency
* Methods [[beginCache()]] and [[endCache()]] can be used as shortcuts to turn on
* and off query caching on the fly.
* @see queryCacheDuration
* @see queryCacheID
* @see queryCacheDependency
* @see beginCache()
* @see endCache()
*/
public
$
queryCachingDuration
=
-
1
;
public
$
enableQueryCache
=
false
;
/**
* @var \yii\caching\Dependency the dependency that will be used when saving query results into cache.
* Defaults to null, meaning no dependency.
* @see queryCachingDuration
* @var integer number of seconds that query results can remain valid in cache.
* Defaults to 3600, meaning one hour.
* Use 0 to indicate that the cached data will never expire.
* @see enableQueryCache
*/
public
$queryCach
ingDependency
;
public
$queryCach
eDuration
=
3600
;
/**
* @var integer the number of SQL statements that need to be cached when they are executed next.
* Defaults to 0, meaning the query result of the next SQL statement will NOT be cached.
* Note that each time after executing a SQL statement (whether executed on DB server or fetched from
* query cache), this property will be reduced by 1 until 0.
* @see queryCachingDuration
* @var \yii\caching\Dependency the dependency that will be used when saving query results into cache.
* Defaults to null, meaning no dependency.
* @see enableQueryCache
*/
public
$queryCach
ingCount
=
0
;
public
$queryCach
eDependency
;
/**
* @var string the ID of the cache application component that is used for query caching.
* Defaults to 'cache'.
* @see
queryCachingDuration
* @see
enableQueryCache
*/
public
$queryCacheID
=
'cache'
;
/**
...
...
@@ -297,24 +298,29 @@ class Connection extends \yii\base\ApplicationComponent
}
/**
* Sets the parameters about query caching.
* This method is provided as a shortcut to setting three properties that are related
* with query caching: [[queryCachingDuration]], [[queryCachingDependency]] and
* [[queryCachingCount]].
* Turns on query caching.
* This method is provided as a shortcut to setting two properties that are related
* with query caching: [[queryCacheDuration]] and [[queryCacheDependency]].
* @param integer $duration the number of seconds that query results may remain valid in cache.
* See [[queryCach
ing
Duration]] for more details.
* See [[queryCach
e
Duration]] for more details.
* @param \yii\caching\Dependency $dependency the dependency for the cached query result.
* See [[queryCachingDependency]] for more details.
* @param integer $queryCount the number of SQL queries that need to be cached after calling this method.
* See [[queryCachingCount]] for more details.
* @return Connection the connection instance itself.
* See [[queryCacheDependency]] for more details.
*/
public
function
beginCache
(
$duration
=
null
,
$dependency
=
null
)
{
$this
->
enableQueryCache
=
true
;
if
(
$duration
!==
null
)
{
$this
->
queryCacheDuration
=
$duration
;
}
$this
->
queryCacheDependency
=
$dependency
;
}
/**
* Turns off query caching.
*/
public
function
cache
(
$duration
=
300
,
$dependency
=
null
,
$queryCount
=
1
)
public
function
endCache
(
)
{
$this
->
queryCachingDuration
=
$duration
;
$this
->
queryCachingDependency
=
$dependency
;
$this
->
queryCachingCount
=
$queryCount
;
return
$this
;
$this
->
enableQueryCache
=
false
;
}
/**
...
...
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