From 4d16e30a16d4cfc1ee45ac6f7279bdcd2b64d3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 2 Sep 2016 09:53:41 +0000 Subject: [PATCH] Use microtime to have more precision on cache time --- UPGRADE.md | 6 ++++++ lib/Doctrine/ORM/Cache/QueryCacheEntry.php | 6 +++--- lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php | 2 +- tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index ed9a538b3..2195f5b82 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # Upgrade to 2.5 +## Minor BC BREAK: query cache key time is now a float + +As of 2.5, the `QueryCacheEntry#time` property will contain a float value +instead of an integer in order to have more precision and also to be consistent +with the `TimestampCacheEntry#time`. + ## Minor BC BREAK: discriminator map must now include all non-transient classes It is now required that you declare the root of an inheritance in the diff --git a/lib/Doctrine/ORM/Cache/QueryCacheEntry.php b/lib/Doctrine/ORM/Cache/QueryCacheEntry.php index 1ba61bcf0..a8a26f6d2 100644 --- a/lib/Doctrine/ORM/Cache/QueryCacheEntry.php +++ b/lib/Doctrine/ORM/Cache/QueryCacheEntry.php @@ -38,18 +38,18 @@ class QueryCacheEntry implements CacheEntry /** * READ-ONLY: Public only for performance reasons, it should be considered immutable. * - * @var integer Time creation of this cache entry + * @var float Time creation of this cache entry */ public $time; /** * @param array $result - * @param integer $time + * @param float $time */ public function __construct($result, $time = null) { $this->result = $result; - $this->time = $time ?: time(); + $this->time = $time ?: microtime(true); } /** diff --git a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php index 4e504e4f8..71ac3e828 100644 --- a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php +++ b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php @@ -35,6 +35,6 @@ class TimestampQueryCacheValidator implements QueryCacheValidator return true; } - return ($entry->time + $key->lifetime) > time(); + return ($entry->time + $key->lifetime) > microtime(true); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 3af1a3bc4..ad1da8d1b 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -386,7 +386,7 @@ class DefaultQueryCacheTest extends OrmTestCase array('id'=>2, 'name' => 'Bar') ); - $entry->time = time() - 100; + $entry->time = microtime(true) - 100; $this->region->addReturn('get', $entry); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0]));