Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
da38026b
Commit
da38026b
authored
Oct 22, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-47] Added ability to set the result cache id used to store the cache entry
parent
93e6cabe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
6 deletions
+53
-6
AbstractQuery.php
lib/Doctrine/ORM/AbstractQuery.php
+40
-4
ResultCacheTest.php
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
+13
-2
No files found.
lib/Doctrine/ORM/AbstractQuery.php
View file @
da38026b
...
...
@@ -94,6 +94,13 @@ abstract class AbstractQuery
*/
protected
$_resultCache
;
/**
* The id to store the result cache entry under.
*
* @var string
*/
protected
$_resultCacheId
;
/**
* @var boolean Boolean value that indicates whether or not expire the result cache.
*/
...
...
@@ -437,9 +444,8 @@ abstract class AbstractQuery
// Check result cache
if
(
$cacheDriver
=
$this
->
getResultCacheDriver
())
{
// Calculate hash for DQL query.
$hash
=
md5
(
$this
->
getDql
()
.
var_export
(
$params
,
true
));
$cached
=
(
$this
->
_expireResultCache
)
?
false
:
$cacheDriver
->
fetch
(
$hash
);
$id
=
$this
->
_getResultCacheId
(
$params
);
$cached
=
(
$this
->
_expireResultCache
)
?
false
:
$cacheDriver
->
fetch
(
$id
);
if
(
$cached
===
false
)
{
// Cache miss.
...
...
@@ -449,7 +455,7 @@ abstract class AbstractQuery
$stmt
,
$this
->
_resultSetMapping
,
$this
->
_hints
);
$cacheDriver
->
save
(
$
hash
,
$result
,
$this
->
_resultCacheTTL
);
$cacheDriver
->
save
(
$
id
,
$result
,
$this
->
_resultCacheTTL
);
return
$result
;
}
else
{
...
...
@@ -469,6 +475,36 @@ abstract class AbstractQuery
);
}
/**
* Set the result cache id to use to store the result set cache entry.
* If this is not explicitely set by the developer then a hash is automatically
* generated for you.
*
* @param string $id
* @return void
*/
public
function
setResultCacheId
(
$id
)
{
$this
->
_resultCacheId
=
$id
;
}
/**
* Get the result cache id to use to store the result set cache entry.
* Will return the configured id if it exists otherwise a hash will be
* automatically generated for you.
*
* @param array $params
* @return string $id
*/
protected
function
_getResultCacheId
(
array
$params
)
{
if
(
$this
->
_resultCacheId
)
{
return
$this
->
_resultCacheId
;
}
else
{
return
md5
(
$this
->
getDql
()
.
var_export
(
$params
,
true
));
}
}
/**
* Prepares the given parameters for execution in an SQL statement.
*
...
...
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
View file @
da38026b
...
...
@@ -19,7 +19,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
parent
::
setUp
();
}
public
function
test
Query
Cache
()
public
function
test
Result
Cache
()
{
$user
=
new
CmsUser
;
$user
->
name
=
'Roman'
;
...
...
@@ -55,5 +55,16 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertEquals
(
1
,
count
(
$users
));
$this
->
assertEquals
(
'Roman'
,
$users
[
0
]
->
name
);
}
}
public
function
testSetResultCacheId
()
{
$cache
=
new
ArrayCache
;
$query
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$query
->
setResultCache
(
$cache
);
$query
->
setResultCacheId
(
'testing_result_cache_id'
);
$users
=
$query
->
getResult
();
$this
->
assertTrue
(
$cache
->
contains
(
'testing_result_cache_id'
));
}
}
\ No newline at end of file
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