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
27132ced
Commit
27132ced
authored
Jul 21, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4384.
parent
98a86ce7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
19 deletions
+21
-19
caching-data.md
docs/guide/caching-data.md
+1
-1
Command.php
framework/db/Command.php
+0
-1
Connection.php
framework/db/Connection.php
+20
-17
No files found.
docs/guide/caching-data.md
View file @
27132ced
...
...
@@ -267,7 +267,7 @@ Query caching can be used for [DAO](db-dao.md) as well as [ActiveRecord](db-acti
Query caching has three global configurable options through
[
[yii\db\Connection
]
]:
*
[
[yii\db\Connection::enableQueryCache|enableQueryCache
]
]: whether to turn on or off query caching.
It defaults to
fals
e. Note that to effectively turn on query caching, you also need to have a valid
It defaults to
tru
e. Note that to effectively turn on query caching, you also need to have a valid
cache, as specified by
[
[yii\db\Connection::queryCache|queryCache
]
].
*
[
[yii\db\Connection::queryCacheDuration|queryCacheDuration
]
]: this represents the number of seconds
that a query result can remain valid in the cache. You can use 0 to indicate a query result should
...
...
framework/db/Command.php
View file @
27132ced
...
...
@@ -852,7 +852,6 @@ class Command extends Component
Yii
::
endProfile
(
$token
,
'yii\db\Command::query'
);
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
'yii\db\Command::query'
);
$this
->
db
->
resetQueryCacheInfo
();
throw
$this
->
db
->
getSchema
()
->
convertException
(
$e
,
$rawSql
);
}
...
...
framework/db/Connection.php
View file @
27132ced
...
...
@@ -204,11 +204,12 @@ class Connection extends Component
* @var boolean whether to enable query caching.
* Note that in order to enable query caching, a valid cache component as specified
* by [[queryCache]] must be enabled and [[enableQueryCache]] must be set true.
* Also, only the results of the queries enclosed within [[cache()]] will be cached.
* @see queryCache
* @see cache()
* @see noCache()
*/
public
$enableQueryCache
=
fals
e
;
public
$enableQueryCache
=
tru
e
;
/**
* @var integer the default number of seconds that query results can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
...
...
@@ -399,6 +400,7 @@ class Connection extends Component
* Use 0 to indicate that the cached data will never expire.
* @param \yii\caching\Dependency $dependency the cache dependency associated with the cached query results.
* @return mixed the return result of the callable
* @throws \Exception if there is any exception during query
* @see enableQueryCache
* @see queryCache
* @see noCache()
...
...
@@ -406,9 +408,14 @@ class Connection extends Component
public
function
cache
(
callable
$callable
,
$duration
=
null
,
$dependency
=
null
)
{
$this
->
_queryCacheInfo
[]
=
[
$duration
===
null
?
$this
->
queryCacheDuration
:
$duration
,
$dependency
];
$result
=
call_user_func
(
$callable
,
$this
);
array_pop
(
$this
->
_queryCacheInfo
);
return
$result
;
try
{
$result
=
call_user_func
(
$callable
,
$this
);
array_pop
(
$this
->
_queryCacheInfo
);
return
$result
;
}
catch
(
\Exception
$e
)
{
array_pop
(
$this
->
_queryCacheInfo
);
throw
$e
;
}
}
/**
...
...
@@ -430,6 +437,7 @@ class Connection extends Component
* @param callable $callable a PHP callable that contains DB queries which should not use query cache.
* The signature of the callable is `function (Connection $db)`.
* @return mixed the return result of the callable
* @throws \Exception if there is any exception during query
* @see enableQueryCache
* @see queryCache
* @see cache()
...
...
@@ -437,9 +445,14 @@ class Connection extends Component
public
function
noCache
(
callable
$callable
)
{
$this
->
_queryCacheInfo
[]
=
false
;
$result
=
call_user_func
(
$callable
,
$this
);
array_pop
(
$this
->
_queryCacheInfo
);
return
$result
;
try
{
$result
=
call_user_func
(
$callable
,
$this
);
array_pop
(
$this
->
_queryCacheInfo
);
return
$result
;
}
catch
(
\Exception
$e
)
{
array_pop
(
$this
->
_queryCacheInfo
);
throw
$e
;
}
}
/**
...
...
@@ -461,16 +474,6 @@ class Connection extends Component
}
/**
* Cleans up the query cache information.
* This method is used internally by [[Command]].
* @internal
*/
public
function
resetQueryCacheInfo
()
{
$this
->
_queryCacheInfo
=
[];
}
/**
* Establishes a DB connection.
* It does nothing if a DB connection has already been established.
* @throws Exception if connection fails
...
...
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