From 1ad982a4fe2205a013ccbd864aedbc36f3ba370e Mon Sep 17 00:00:00 2001 From: hobodave Date: Fri, 29 Jan 2010 01:38:37 +0000 Subject: [PATCH] [2.0][DC-460] Refactored cache bulk deletion methods to use driver specific features to retrieve list of keys. Also, refactored tests so that all methods are tested for all drivers. Removed: - Doctrine\Common\Cache\AbstractCache::count() - Doctrine\Common\Cache\AbstractCache::deleteAll() API Changes: - Doctrine\ORM\AbstractQuery::getResultCacheId() now public Bugs fixed: - Doctrine\Common\Cache\AbstractCache::deleteByPrefix() was deleting _every_ key in cache --- lib/Doctrine/Common/Cache/AbstractCache.php | 137 ++---------------- lib/Doctrine/Common/Cache/ApcCache.php | 21 ++- lib/Doctrine/Common/Cache/ArrayCache.php | 15 +- lib/Doctrine/Common/Cache/MemcacheCache.php | 28 +++- lib/Doctrine/Common/Cache/XcacheCache.php | 41 +++++- lib/Doctrine/ORM/AbstractQuery.php | 36 ++--- .../Tests/Common/Cache/ApcCacheTest.php | 21 +-- .../Tests/Common/Cache/ArrayCacheTest.php | 28 +--- .../Doctrine/Tests/Common/Cache/CacheTest.php | 61 ++++---- .../Tests/Common/Cache/MemcacheCacheTest.php | 25 +--- .../Tests/Common/Cache/XcacheCacheTest.php | 20 +-- .../Tests/ORM/Functional/QueryCacheTest.php | 20 +-- .../Tests/ORM/Functional/ResultCacheTest.php | 14 +- 13 files changed, 188 insertions(+), 279 deletions(-) diff --git a/lib/Doctrine/Common/Cache/AbstractCache.php b/lib/Doctrine/Common/Cache/AbstractCache.php index 96399ef06..ab8146b4e 100644 --- a/lib/Doctrine/Common/Cache/AbstractCache.php +++ b/lib/Doctrine/Common/Cache/AbstractCache.php @@ -39,36 +39,6 @@ abstract class AbstractCache implements Cache /** @var string The namespace to prefix all cache ids with */ private $_namespace = null; - - /** @var boolean Whether to manage cache keys or not. */ - private $_manageCacheIds = false; - - /** - * Sets whether cache keys should be managed by the cache driver - * separately from the cache entries. This allows more granular - * cache clearing through {@link deleteByPrefix}, {@link deleteByRegex}, - * {@link deleteBySuffix} and some other operations such as {@link count} - * and {@link getIds}. Managing cache keys comes at the cost of a higher - * probability for cache slams due to the single cache key used for - * managing all other keys. - * - * @param boolean $bool - */ - public function setManageCacheIds($bool) - { - $this->_manageCacheIds = $bool; - } - - /** - * Checks whether cache keys are managed by this cache driver. - * - * @return boolean - * @see setManageCacheIds() - */ - public function getManageCacheIds() - { - return $this->_manageCacheIds; - } /** * Set the namespace to prefix all cache ids with. @@ -103,14 +73,7 @@ abstract class AbstractCache implements Cache public function save($id, $data, $lifeTime = false) { $id = $this->_getNamespacedId($id); - if ($this->_doSave($id, $data, $lifeTime)) { - if ($this->_manageCacheIds) { - $this->_saveId($id); - } - - return true; - } - return false; + return $this->_doSave($id, $data, $lifeTime); } /** @@ -124,14 +87,7 @@ abstract class AbstractCache implements Cache return $this->deleteByRegex('/' . str_replace('*', '.*', $id) . '/'); } - if ($this->_doDelete($id)) { - if ($this->_manageCacheIds) { - $this->_deleteId($id); - } - - return true; - } - return false; + return $this->_doDelete($id); } /** @@ -141,7 +97,6 @@ abstract class AbstractCache implements Cache */ public function deleteAll() { - $this->_errorIfCacheIdsNotManaged(); $ids = $this->getIds(); foreach ($ids as $id) { $this->delete($id); @@ -157,7 +112,6 @@ abstract class AbstractCache implements Cache */ public function deleteByRegex($regex) { - $this->_errorIfCacheIdsNotManaged(); $deleted = array(); $ids = $this->getIds(); foreach ($ids as $id) { @@ -177,11 +131,10 @@ abstract class AbstractCache implements Cache */ public function deleteByPrefix($prefix) { - $this->_errorIfCacheIdsNotManaged(); $deleted = array(); $ids = $this->getIds(); foreach ($ids as $id) { - if (strpos($id, $prefix) == 0) { + if (strpos($id, $prefix) === 0) { $this->delete($id); $deleted[] = $id; } @@ -192,16 +145,15 @@ abstract class AbstractCache implements Cache /** * Delete cache entries where the id has the passed suffix * - * @param string $suffix + * @param string $suffix * @return array $deleted Array of the deleted cache ids */ public function deleteBySuffix($suffix) { - $this->_errorIfCacheIdsNotManaged(); $deleted = array(); $ids = $this->getIds(); foreach ($ids as $id) { - if (substr($id, -1 * strlen($suffix)) == $suffix) { + if (substr($id, -1 * strlen($suffix)) === $suffix) { $this->delete($id); $deleted[] = $id; } @@ -209,30 +161,6 @@ abstract class AbstractCache implements Cache return $deleted; } - /** - * Count and return the number of cache entries. - * - * @return integer $count - */ - public function count() - { - $this->_errorIfCacheIdsNotManaged(); - $ids = $this->getIds(); - return $ids ? count($ids) : 0; - } - - /** - * Get an array of all the cache ids stored - * - * @return array $ids - */ - public function getIds() - { - $this->_errorIfCacheIdsNotManaged(); - $ids = $this->fetch($this->_cacheIdsIndexId); - return $ids ? $ids : array(); - } - /** * Prefix the passed id with the configured namespace value * @@ -248,53 +176,9 @@ abstract class AbstractCache implements Cache } } - /** - * Save a cache id to the index of cache ids - * - * @param string $id - * @return boolean TRUE if the id was successfully stored in the cache, FALSE otherwise. - */ - private function _saveId($id) - { - $ids = $this->getIds(); - $ids[] = $id; - - $cacheIdsIndexId = $this->_getNamespacedId($this->_cacheIdsIndexId); - return $this->_doSave($cacheIdsIndexId, $ids, null); - } - - /** - * Delete a cache id from the index of cache ids - * - * @param string $id - * @return boolean TRUE if the entry was successfully removed from the cache, FALSE otherwise. - */ - private function _deleteId($id) - { - $ids = $this->getIds(); - $key = array_search($id, $ids); - if ($key !== false) { - unset($ids[$key]); - - $cacheIdsIndexId = $this->_getNamespacedId($this->_cacheIdsIndexId); - return $this->_doSave($cacheIdsIndexId, $ids, null); - } - return false; - } - - /** - * @throws BadMethodCallException If the cache driver does not manage cache keys. - */ - private function _errorIfCacheIdsNotManaged() - { - if ( ! $this->_manageCacheIds) { - throw new \BadMethodCallException("Operation not supported if cache keys are not managed."); - } - } - /** * Fetches an entry from the cache. - * + * * @param string $id cache id The id of the cache entry to fetch. * @return string The cached data or FALSE, if no cache entry exists for the given id. */ @@ -320,9 +204,16 @@ abstract class AbstractCache implements Cache /** * Deletes a cache entry. - * + * * @param string $id cache id * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise. */ abstract protected function _doDelete($id); + + /** + * Get an array of all the cache ids stored + * + * @return array $ids + */ + abstract public function getIds(); } \ No newline at end of file diff --git a/lib/Doctrine/Common/Cache/ApcCache.php b/lib/Doctrine/Common/Cache/ApcCache.php index 32674a558..34e67d47a 100644 --- a/lib/Doctrine/Common/Cache/ApcCache.php +++ b/lib/Doctrine/Common/Cache/ApcCache.php @@ -31,13 +31,28 @@ namespace Doctrine\Common\Cache; * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * @author David Abdemoulaie */ class ApcCache extends AbstractCache { /** * {@inheritdoc} */ - protected function _doFetch($id) + public function getIds() + { + $ci = apc_cache_info('user'); + $keys = array(); + + foreach ($ci['cache_list'] as $entry) { + $keys[] = $entry['info']; + } + return $keys; + } + + /** + * {@inheritdoc} + */ + protected function _doFetch($id) { return apc_fetch($id); } @@ -45,7 +60,7 @@ class ApcCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doContains($id) + protected function _doContains($id) { $found = false; apc_fetch($id, $found); @@ -63,7 +78,7 @@ class ApcCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doDelete($id) + protected function _doDelete($id) { return apc_delete($id); } diff --git a/lib/Doctrine/Common/Cache/ArrayCache.php b/lib/Doctrine/Common/Cache/ArrayCache.php index 636379fb6..f9e15b2a6 100644 --- a/lib/Doctrine/Common/Cache/ArrayCache.php +++ b/lib/Doctrine/Common/Cache/ArrayCache.php @@ -31,19 +31,28 @@ namespace Doctrine\Common\Cache; * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * @author David Abdemoulaie */ class ArrayCache extends AbstractCache { /** * @var array $data */ - private $data; + private $data = array(); /** * {@inheritdoc} */ - protected function _doFetch($id) - { + public function getIds() + { + return array_keys($this->data); + } + + /** + * {@inheritdoc} + */ + protected function _doFetch($id) + { if (isset($this->data[$id])) { return $this->data[$id]; } diff --git a/lib/Doctrine/Common/Cache/MemcacheCache.php b/lib/Doctrine/Common/Cache/MemcacheCache.php index 3ccb3e7a5..f819daf94 100644 --- a/lib/Doctrine/Common/Cache/MemcacheCache.php +++ b/lib/Doctrine/Common/Cache/MemcacheCache.php @@ -33,6 +33,7 @@ use \Memcache; * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * @author David Abdemoulaie */ class MemcacheCache extends AbstractCache { @@ -64,7 +65,28 @@ class MemcacheCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doFetch($id) + public function getIds() + { + $keys = array(); + $allSlabs = $this->_memcache->getExtendedStats('slabs'); + + foreach ($allSlabs as $server => $slabs) { + foreach (array_keys($slabs) as $slabId) { + $dump = $this->_memcache->getExtendedStats('cachedump', (int) $slabId); + foreach ($dump as $entries) { + if ($entries) { + $keys = array_merge($keys, array_keys($entries)); + } + } + } + } + return $keys; + } + + /** + * {@inheritdoc} + */ + protected function _doFetch($id) { return $this->_memcache->get($id); } @@ -72,7 +94,7 @@ class MemcacheCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doContains($id) + protected function _doContains($id) { return (bool) $this->_memcache->get($id); } @@ -88,7 +110,7 @@ class MemcacheCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doDelete($id) + protected function _doDelete($id) { return $this->_memcache->delete($id); } diff --git a/lib/Doctrine/Common/Cache/XcacheCache.php b/lib/Doctrine/Common/Cache/XcacheCache.php index dcba81210..d150d98de 100644 --- a/lib/Doctrine/Common/Cache/XcacheCache.php +++ b/lib/Doctrine/Common/Cache/XcacheCache.php @@ -31,13 +31,32 @@ namespace Doctrine\Common\Cache; * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * @author David Abdemoulaie */ class XcacheCache extends AbstractCache { /** * {@inheritdoc} */ - protected function _doFetch($id) + public function getIds() + { + $this->_checkAuth(); + $keys = array(); + for ($i = 0, $count = xcache_count(XC_TYPE_VAR); $i < $count; $i++) { + $entries = xcache_list(XC_TYPE_VAR, $i); + if (is_array($entries['cache_list'])) { + foreach ($entries['cache_list'] as $entry) { + $keys[] = $entry['name']; + } + } + } + return $keys; + } + + /** + * {@inheritdoc} + */ + protected function _doFetch($id) { return $this->_doContains($id) ? xcache_get($id) : false; } @@ -45,7 +64,7 @@ class XcacheCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doContains($id) + protected function _doContains($id) { return xcache_isset($id); } @@ -61,8 +80,22 @@ class XcacheCache extends AbstractCache /** * {@inheritdoc} */ - protected function _doDelete($id) + protected function _doDelete($id) { - return xcache_unset($id); + return xcache_unset($id); + } + + + /** + * Checks that xcache.admin.enable_auth is Off + * + * @throws \BadMethodCallException When xcache.admin.enable_auth is On + * @return void + */ + protected function _checkAuth() + { + if (ini_get('xcache.admin.enable_auth')) { + throw new \BadMethodCallException('To use all features of \Doctrine\Common\Cache\XcacheCache, you must set "xcache.admin.enable_auth" to "Off" in your php.ini.'); + } } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 576c3a296..5d7a5470b 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -158,10 +158,10 @@ abstract class AbstractQuery } return $this->_params; } - + /** * Gets a query parameter. - * + * * @param mixed $key The key (index or name) of the bound parameter. * @return mixed The value of the bound parameter. */ @@ -178,7 +178,7 @@ abstract class AbstractQuery * @return string SQL query */ abstract public function getSql(); - + /** * Sets a query parameter. * @@ -191,7 +191,7 @@ abstract class AbstractQuery $this->_params[$key] = $value; return $this; } - + /** * Sets a collection of query parameters. * @@ -375,9 +375,9 @@ abstract class AbstractQuery /** * Gets the single result of the query. - * + * * Enforces the presence as well as the uniqueness of the result. - * + * * If the result is not unique, a NonUniqueResultException is thrown. * If there is no result, a NoResultException is thrown. * @@ -389,11 +389,11 @@ abstract class AbstractQuery public function getSingleResult($hydrationMode = null) { $result = $this->execute(array(), $hydrationMode); - + if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { throw new NoResultException; } - + if (is_array($result)) { if (count($result) > 1) { throw new NonUniqueResultException; @@ -405,7 +405,7 @@ abstract class AbstractQuery } return $result->first(); } - + return $result; } @@ -479,26 +479,26 @@ abstract class AbstractQuery if ($hydrationMode !== null) { $this->_hydrationMode = $hydrationMode; } - + $params = $this->getParameters($params); - + if (isset($params[0])) { throw QueryException::invalidParameterPosition(0); } // Check result cache if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) { - $id = $this->_getResultCacheId($params); + $id = $this->getResultCacheId($params); $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id); if ($cached === false) { // Cache miss. $stmt = $this->_doExecute($params); - + $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll( $stmt, $this->_resultSetMapping, $this->_hints ); - + $cacheDriver->save($id, $result, $this->_resultCacheTTL); return $result; @@ -538,10 +538,10 @@ abstract class AbstractQuery * Will return the configured id if it exists otherwise a hash will be * automatically generated for you. * - * @param array $params + * @param array $params * @return string $id */ - protected function _getResultCacheId(array $params) + public function getResultCacheId(array $params) { if ($this->_resultCacheId) { return $this->_resultCacheId; @@ -552,11 +552,11 @@ abstract class AbstractQuery /** * Prepares the given parameters for execution in an SQL statement. - * + * * Note to inheritors: This method must return a numerically, continuously indexed array, * starting with index 0 where the values (the parameter values) are in the order * in which the parameters appear in the SQL query. - * + * * @return array The SQL parameter array. */ abstract protected function _prepareParams(array $params); diff --git a/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php b/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php index 556068d39..f52f5410f 100644 --- a/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php @@ -6,7 +6,7 @@ use Doctrine\Common\Cache\ApcCache; require_once __DIR__ . '/../../TestInit.php'; -class ApcCacheTest extends \Doctrine\Tests\DoctrineTestCase +class ApcCacheTest extends CacheTest { public function setUp() { @@ -15,23 +15,8 @@ class ApcCacheTest extends \Doctrine\Tests\DoctrineTestCase } } - public function testApcCacheDriver() + protected function _getCacheDriver() { - $cache = new ApcCache(); - - // Test save - $cache->save('test_key', 'testing this out'); - - // Test contains to test that save() worked - $this->assertTrue($cache->contains('test_key')); - - // Test fetch - $this->assertEquals('testing this out', $cache->fetch('test_key')); - - // Test delete - $cache->save('test_key2', 'test2'); - - $cache->delete('test_key2'); - $this->assertFalse($cache->contains('test_key2')); + return new ApcCache(); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php b/tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php index 18a750f7f..1bb2cb4f2 100644 --- a/tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php @@ -6,32 +6,10 @@ use Doctrine\Common\Cache\ArrayCache; require_once __DIR__ . '/../../TestInit.php'; -class ArrayCacheTest extends \Doctrine\Tests\DoctrineTestCase +class ArrayCacheTest extends CacheTest { - public function testArrayCacheDriver() + protected function _getCacheDriver() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); - - // Test save - $cache->save('test_key', 'testing this out'); - - // Test contains to test that save() worked - $this->assertTrue($cache->contains('test_key')); - - // Test fetch - $this->assertEquals('testing this out', $cache->fetch('test_key')); - - // Test count - $this->assertEquals(1, $cache->count()); - - // Test delete - $cache->save('test_key2', 'test2'); - $cache->delete('test_key2'); - $this->assertFalse($cache->contains('test_key2')); - - // Test delete all - $cache->deleteAll(); - $this->assertEquals(0, $cache->count()); + return new ArrayCache(); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/CacheTest.php b/tests/Doctrine/Tests/Common/Cache/CacheTest.php index 088ead22e..32bf386b5 100644 --- a/tests/Doctrine/Tests/Common/Cache/CacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/CacheTest.php @@ -2,80 +2,87 @@ namespace Doctrine\Tests\Common\Cache; -use Doctrine\Common\Cache\ArrayCache; - require_once __DIR__ . '/../../TestInit.php'; -class CacheTest extends \Doctrine\Tests\DoctrineTestCase +abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase { - public function testCount() + public function testBasics() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); - $cache->save('test_key1', '1'); - $cache->save('test_key2', '2'); - $this->assertEquals($cache->count(), 2); + $cache = $this->_getCacheDriver(); + + // Test save + $cache->save('test_key', 'testing this out'); + + // Test contains to test that save() worked + $this->assertTrue($cache->contains('test_key')); + + // Test fetch + $this->assertEquals('testing this out', $cache->fetch('test_key')); + + // Test delete + $cache->save('test_key2', 'test2'); + $cache->delete('test_key2'); + $this->assertFalse($cache->contains('test_key2')); } public function testDeleteAll() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->save('test_key1', '1'); $cache->save('test_key2', '2'); $cache->deleteAll(); - $this->assertEquals($cache->count(), 0); + $this->assertFalse($cache->contains('test_key1')); + $this->assertFalse($cache->contains('test_key2')); } public function testDeleteByRegex() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->save('test_key1', '1'); $cache->save('test_key2', '2'); $cache->deleteByRegex('/test_key[0-9]/'); - $this->assertEquals($cache->count(), 0); + $this->assertFalse($cache->contains('test_key1')); + $this->assertFalse($cache->contains('test_key2')); } public function testDeleteByPrefix() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->save('test_key1', '1'); $cache->save('test_key2', '2'); $cache->deleteByPrefix('test_key'); - $this->assertEquals($cache->count(), 0); + $this->assertFalse($cache->contains('test_key1')); + $this->assertFalse($cache->contains('test_key2')); } public function testDeleteBySuffix() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->save('1test_key', '1'); $cache->save('2test_key', '2'); $cache->deleteBySuffix('test_key'); - $this->assertEquals($cache->count(), 0); + $this->assertFalse($cache->contains('1test_key')); + $this->assertFalse($cache->contains('2test_key')); } public function testDeleteByWildcard() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->save('test_key1', '1'); $cache->save('test_key2', '2'); $cache->delete('test_key*'); - $this->assertEquals($cache->count(), 0); + $this->assertFalse($cache->contains('test_key1')); + $this->assertFalse($cache->contains('test_key2')); } public function testNamespace() { - $cache = new ArrayCache(); - $cache->setManageCacheIds(true); + $cache = $this->_getCacheDriver(); $cache->setNamespace('test_'); $cache->save('key1', 'test'); $this->assertTrue($cache->contains('key1')); @@ -83,4 +90,6 @@ class CacheTest extends \Doctrine\Tests\DoctrineTestCase $ids = $cache->getIds(); $this->assertTrue(in_array('test_key1', $ids)); } + + abstract protected function _getCacheDriver(); } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php index 2972e2292..b176ce95a 100644 --- a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php @@ -6,10 +6,10 @@ use Doctrine\Common\Cache\MemcacheCache; require_once __DIR__ . '/../../TestInit.php'; -class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase +class MemcacheCacheTest extends CacheTest { private $_memcache; - + public function setUp() { if (extension_loaded('memcache')) { @@ -23,23 +23,10 @@ class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase } } - public function testMemcacheCacheDriver() + protected function _getCacheDriver() { - $cache = new MemcacheCache(); - $cache->setMemcache($this->_memcache); - - // Test save - $cache->save('test_key', 'testing this out'); - - // Test contains to test that save() worked - $this->assertTrue($cache->contains('test_key')); - - // Test fetch - $this->assertEquals('testing this out', $cache->fetch('test_key')); - - // Test delete - $cache->save('test_key2', 'test2'); - $cache->delete('test_key2'); - $this->assertFalse($cache->contains('test_key2')); + $driver = new MemcacheCache(); + $driver->setMemcache($this->_memcache); + return $driver; } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php b/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php index bd97a6ec5..d70882335 100644 --- a/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php @@ -6,7 +6,7 @@ use Doctrine\Common\Cache\XcacheCache; require_once __DIR__ . '/../../TestInit.php'; -class XcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase +class XcacheCacheTest extends CacheTest { public function setUp() { @@ -15,22 +15,8 @@ class XcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase } } - public function testXcacheCacheDriver() + protected function _getCacheDriver() { - $cache = new XcacheCache(); - - // Test save - $cache->save('test_key', 'testing this out'); - - // Test contains to test that save() worked - $this->assertTrue($cache->contains('test_key')); - - // Test fetch - $this->assertEquals('testing this out', $cache->fetch('test_key')); - - // Test delete - $cache->save('test_key2', 'test2'); - $cache->delete('test_key2'); - $this->assertFalse($cache->contains('test_key2')); + return new XcacheCache(); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 0f0f3fe13..e7971cf9b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -22,7 +22,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testQueryCache() { $this->_em->getConfiguration()->setQueryCacheImpl(null); - + $user = new CmsUser; $user->name = 'Roman'; $user->username = 'romanb'; @@ -33,26 +33,22 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $cache = new ArrayCache; - $cache->setManageCacheIds(true); $query->setQueryCacheDriver($cache); - $this->assertEquals(0, $cache->count()); - + $users = $query->getResult(); - $this->assertEquals(1, $cache->count()); - $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); + $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); $this->assertEquals(1, count($users)); $this->assertEquals('Roman', $users[0]->name); - + $this->_em->clear(); - + $query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $query2->setQueryCacheDriver($cache); - + $users = $query2->getResult(); - - $this->assertEquals(1, $cache->count()); - $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); + + $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); $this->assertEquals(1, count($users)); $this->assertEquals('Roman', $users[0]->name); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 4de48b0aa..7e4a919a5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -31,24 +31,22 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $cache = new ArrayCache; - $cache->setManageCacheIds(true); $query->setResultCacheDriver($cache); - $this->assertEquals(0, $cache->count()); - + $users = $query->getResult(); - $this->assertEquals(1, $cache->count()); + $this->assertTrue($cache->contains($query->getResultCacheId(array()))); $this->assertEquals(1, count($users)); $this->assertEquals('Roman', $users[0]->name); - + $this->_em->clear(); - + $query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $query2->setResultCacheDriver($cache); - + $users = $query2->getResult(); - $this->assertEquals(1, $cache->count()); + $this->assertTrue($cache->contains($query->getResultCacheId(array()))); $this->assertEquals(1, count($users)); $this->assertEquals('Roman', $users[0]->name); }