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
ccf27a38
Commit
ccf27a38
authored
Oct 24, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Minor fixes to cache drivers and result set cache implementation
parent
a4913774
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
47 deletions
+81
-47
AbstractCache.php
lib/Doctrine/Common/Cache/AbstractCache.php
+16
-16
ApcCache.php
lib/Doctrine/Common/Cache/ApcCache.php
+3
-1
AbstractQuery.php
lib/Doctrine/ORM/AbstractQuery.php
+34
-17
ArrayCacheTest.php
tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php
+1
-1
CacheTest.php
tests/Doctrine/Tests/Common/Cache/CacheTest.php
+7
-7
QueryCacheTest.php
tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php
+1
-1
ResultCacheTest.php
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
+19
-4
No files found.
lib/Doctrine/Common/Cache/AbstractCache.php
View file @
ccf27a38
...
...
@@ -41,7 +41,7 @@ abstract class AbstractCache implements Cache
private
$_namespace
=
null
;
/** @var boolean Whether to manage cache keys or not. */
private
$_manageCache
Key
s
=
false
;
private
$_manageCache
Id
s
=
false
;
/**
* Sets whether cache keys should be managed by the cache driver
...
...
@@ -54,20 +54,20 @@ abstract class AbstractCache implements Cache
*
* @param boolean $bool
*/
public
function
setManageCache
Key
s
(
$bool
)
public
function
setManageCache
Id
s
(
$bool
)
{
$this
->
_manageCache
Key
s
=
$bool
;
$this
->
_manageCache
Id
s
=
$bool
;
}
/**
* Checks whether cache keys are managed by this cache driver.
*
* @return boolean
* @see setManageCache
Key
s()
* @see setManageCache
Id
s()
*/
public
function
getManageCache
Key
s
()
public
function
getManageCache
Id
s
()
{
return
$this
->
_manageCache
Key
s
;
return
$this
->
_manageCache
Id
s
;
}
/**
...
...
@@ -104,7 +104,7 @@ abstract class AbstractCache implements Cache
{
$id
=
$this
->
_getNamespacedId
(
$id
);
if
(
$this
->
_doSave
(
$id
,
$data
,
$lifeTime
))
{
if
(
$this
->
_manageCache
Key
s
)
{
if
(
$this
->
_manageCache
Id
s
)
{
$this
->
_saveId
(
$id
);
}
...
...
@@ -125,7 +125,7 @@ abstract class AbstractCache implements Cache
}
if
(
$this
->
_doDelete
(
$id
))
{
if
(
$this
->
_manageCache
Key
s
)
{
if
(
$this
->
_manageCache
Id
s
)
{
$this
->
_deleteId
(
$id
);
}
...
...
@@ -141,7 +141,7 @@ abstract class AbstractCache implements Cache
*/
public
function
deleteAll
()
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$ids
=
$this
->
getIds
();
foreach
(
$ids
as
$id
)
{
$this
->
delete
(
$id
);
...
...
@@ -157,7 +157,7 @@ abstract class AbstractCache implements Cache
*/
public
function
deleteByRegex
(
$regex
)
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$deleted
=
array
();
$ids
=
$this
->
getIds
();
foreach
(
$ids
as
$id
)
{
...
...
@@ -177,7 +177,7 @@ abstract class AbstractCache implements Cache
*/
public
function
deleteByPrefix
(
$prefix
)
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$deleted
=
array
();
$ids
=
$this
->
getIds
();
foreach
(
$ids
as
$id
)
{
...
...
@@ -197,7 +197,7 @@ abstract class AbstractCache implements Cache
*/
public
function
deleteBySuffix
(
$suffix
)
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$deleted
=
array
();
$ids
=
$this
->
getIds
();
foreach
(
$ids
as
$id
)
{
...
...
@@ -216,7 +216,7 @@ abstract class AbstractCache implements Cache
*/
public
function
count
()
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$ids
=
$this
->
getIds
();
return
$ids
?
count
(
$ids
)
:
0
;
}
...
...
@@ -228,7 +228,7 @@ abstract class AbstractCache implements Cache
*/
public
function
getIds
()
{
$this
->
_errorIfCache
Key
sNotManaged
();
$this
->
_errorIfCache
Id
sNotManaged
();
$ids
=
$this
->
fetch
(
$this
->
_cacheIdsIndexId
);
return
$ids
?
$ids
:
array
();
}
...
...
@@ -285,9 +285,9 @@ abstract class AbstractCache implements Cache
/**
* @throws BadMethodCallException If the cache driver does not manage cache keys.
*/
private
function
_errorIfCache
Key
sNotManaged
()
private
function
_errorIfCache
Id
sNotManaged
()
{
if
(
!
$this
->
_manageCache
Key
s
)
{
if
(
!
$this
->
_manageCache
Id
s
)
{
throw
new
\BadMethodCallException
(
"Operation not supported if cache keys are not managed."
);
}
}
...
...
lib/Doctrine/Common/Cache/ApcCache.php
View file @
ccf27a38
...
...
@@ -47,7 +47,9 @@ class ApcCache extends AbstractCache
*/
protected
function
_doContains
(
$id
)
{
return
apc_fetch
(
$id
)
===
false
?
false
:
true
;
$found
=
false
;
apc_fetch
(
$id
,
$found
);
return
$found
;
}
/**
...
...
lib/Doctrine/ORM/AbstractQuery.php
View file @
ccf27a38
...
...
@@ -92,7 +92,14 @@ abstract class AbstractQuery
*
* @var CacheDriver
*/
protected
$_resultCache
;
protected
$_resultCacheDriver
;
/**
* Boolean flag for whether or not to cache the result sets of this query.
*
* @var boolean
*/
protected
$_useResultCache
;
/**
* The id to store the result cache entry under.
...
...
@@ -211,13 +218,15 @@ abstract class AbstractQuery
* @param Doctrine\Common\Cache\Cache $driver Cache driver
* @return Doctrine\ORM\Query
*/
public
function
setResultCache
(
$resultCache
=
null
)
public
function
setResultCache
Driver
(
$resultCacheDriver
=
null
)
{
if
(
$resultCache
!==
null
&&
!
(
$resultCache
instanceof
\Doctrine\Common\Cache\Cache
))
{
throw
DoctrineException
::
invalidResultCacheObject
(
$resultCache
);
if
(
$resultCacheDriver
!==
null
&&
!
(
$resultCacheDriver
instanceof
\Doctrine\Common\Cache\Cache
))
{
throw
DoctrineException
::
invalidResultCacheObject
(
$resultCacheDriver
);
}
$this
->
_resultCacheDriver
=
$resultCacheDriver
;
if
(
$resultCacheDriver
)
{
$this
->
_useResultCache
=
true
;
}
$this
->
_resultCache
=
$resultCache
;
return
$this
;
}
/**
...
...
@@ -227,18 +236,33 @@ abstract class AbstractQuery
*/
public
function
getResultCacheDriver
()
{
if
(
$this
->
_resultCache
)
{
return
$this
->
_resultCache
;
if
(
$this
->
_resultCache
Driver
)
{
return
$this
->
_resultCache
Driver
;
}
else
{
return
$this
->
_em
->
getConfiguration
()
->
getResultCacheImpl
();
}
}
/**
* Set whether or not to cache the result sets for this query
*
* @param boolean $bool
*/
public
function
useResultCache
(
$bool
,
$timeToLive
=
null
,
$resultCacheId
=
null
)
{
$this
->
_useResultCache
=
$bool
;
if
(
$timeToLive
)
{
$this
->
setResultCacheLifetime
(
$timeToLive
);
}
if
(
$resultCacheId
)
{
$this
->
_resultCacheId
=
$resultCacheId
;
}
}
/**
* Defines how long the result cache will be active before expire.
*
* @param integer $timeToLive How long the cache entry is valid
* @return Doctrine\ORM\Query
*/
public
function
setResultCacheLifetime
(
$timeToLive
)
{
...
...
@@ -247,8 +271,6 @@ abstract class AbstractQuery
}
$this
->
_resultCacheTTL
=
$timeToLive
;
return
$this
;
}
/**
...
...
@@ -270,8 +292,6 @@ abstract class AbstractQuery
public
function
setExpireResultCache
(
$expire
=
true
)
{
$this
->
_expireResultCache
=
$expire
;
return
$this
;
}
/**
...
...
@@ -289,12 +309,10 @@ abstract class AbstractQuery
*
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Query::HYDRATE_* constants.
* @return Doctrine\ORM\Query
*/
public
function
setHydrationMode
(
$hydrationMode
)
{
$this
->
_hydrationMode
=
$hydrationMode
;
return
$this
;
}
/**
...
...
@@ -443,7 +461,7 @@ abstract class AbstractQuery
$params
=
$this
->
getParameters
(
$params
);
// Check result cache
if
(
$cacheDriver
=
$this
->
getResultCacheDriver
())
{
if
(
$
this
->
_useResultCache
&&
$
cacheDriver
=
$this
->
getResultCacheDriver
())
{
$id
=
$this
->
_getResultCacheId
(
$params
);
$cached
=
$this
->
_expireResultCache
?
false
:
$cacheDriver
->
fetch
(
$id
);
...
...
@@ -481,7 +499,6 @@ abstract class AbstractQuery
* generated for you.
*
* @param string $id
* @return void
*/
public
function
setResultCacheId
(
$id
)
{
...
...
tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php
View file @
ccf27a38
...
...
@@ -11,7 +11,7 @@ class ArrayCacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testArrayCacheDriver
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
// Test save
$cache
->
save
(
'test_key'
,
'testing this out'
);
...
...
tests/Doctrine/Tests/Common/Cache/CacheTest.php
View file @
ccf27a38
...
...
@@ -11,7 +11,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testCount
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'test_key1'
,
'1'
);
$cache
->
save
(
'test_key2'
,
'2'
);
$this
->
assertEquals
(
$cache
->
count
(),
2
);
...
...
@@ -20,7 +20,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testDeleteAll
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'test_key1'
,
'1'
);
$cache
->
save
(
'test_key2'
,
'2'
);
$cache
->
deleteAll
();
...
...
@@ -31,7 +31,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testDeleteByRegex
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'test_key1'
,
'1'
);
$cache
->
save
(
'test_key2'
,
'2'
);
$cache
->
deleteByRegex
(
'/test_key[0-9]/'
);
...
...
@@ -42,7 +42,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testDeleteByPrefix
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'test_key1'
,
'1'
);
$cache
->
save
(
'test_key2'
,
'2'
);
$cache
->
deleteByPrefix
(
'test_key'
);
...
...
@@ -53,7 +53,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testDeleteBySuffix
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'1test_key'
,
'1'
);
$cache
->
save
(
'2test_key'
,
'2'
);
$cache
->
deleteBySuffix
(
'test_key'
);
...
...
@@ -64,7 +64,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testDeleteByWildcard
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
save
(
'test_key1'
,
'1'
);
$cache
->
save
(
'test_key2'
,
'2'
);
$cache
->
delete
(
'test_key*'
);
...
...
@@ -75,7 +75,7 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase
public
function
testNamespace
()
{
$cache
=
new
ArrayCache
();
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$cache
->
setNamespace
(
'test_'
);
$cache
->
save
(
'key1'
,
'test'
);
$this
->
assertTrue
(
$cache
->
contains
(
'key1'
));
...
...
tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php
View file @
ccf27a38
...
...
@@ -33,7 +33,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$cache
=
new
ArrayCache
;
$cache
->
setManageCache
Key
s
(
true
);
$cache
->
setManageCache
Id
s
(
true
);
$query
->
setQueryCacheDriver
(
$cache
);
$this
->
assertEquals
(
0
,
$cache
->
count
());
...
...
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
View file @
ccf27a38
...
...
@@ -31,8 +31,8 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$cache
=
new
ArrayCache
;
$cache
->
setManageCache
Key
s
(
true
);
$query
->
setResultCache
(
$cache
);
$cache
->
setManageCache
Id
s
(
true
);
$query
->
setResultCache
Driver
(
$cache
);
$this
->
assertEquals
(
0
,
$cache
->
count
());
$users
=
$query
->
getResult
();
...
...
@@ -44,7 +44,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
_em
->
clear
();
$query2
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$query2
->
setResultCache
(
$cache
);
$query2
->
setResultCache
Driver
(
$cache
);
$users
=
$query2
->
getResult
();
...
...
@@ -58,10 +58,25 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$cache
=
new
ArrayCache
;
$query
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$query
->
setResultCache
(
$cache
);
$query
->
setResultCache
Driver
(
$cache
);
$query
->
setResultCacheId
(
'testing_result_cache_id'
);
$users
=
$query
->
getResult
();
$this
->
assertTrue
(
$cache
->
contains
(
'testing_result_cache_id'
));
}
public
function
testUseResultCache
()
{
$cache
=
new
\Doctrine\Common\Cache\ArrayCache
();
$this
->
_em
->
getConfiguration
()
->
setResultCacheImpl
(
$cache
);
$query
=
$this
->
_em
->
createQuery
(
'select ux from Doctrine\Tests\Models\CMS\CmsUser ux'
);
$query
->
useResultCache
(
true
);
$query
->
setResultCacheId
(
'testing_result_cache_id'
);
$users
=
$query
->
getResult
();
$this
->
assertTrue
(
$cache
->
contains
(
'testing_result_cache_id'
));
$this
->
_em
->
getConfiguration
()
->
setResultCacheImpl
(
null
);
}
}
\ 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