1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Use microtime to have more precision on cache time

This commit is contained in:
Luís Cobucci 2016-09-02 09:53:41 +00:00 committed by Marco Pivetta
parent d592c14a6c
commit 4d16e30a16
4 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,11 @@
# Upgrade to 2.5 # 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 ## 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 It is now required that you declare the root of an inheritance in the

View File

@ -38,18 +38,18 @@ class QueryCacheEntry implements CacheEntry
/** /**
* READ-ONLY: Public only for performance reasons, it should be considered immutable. * 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; public $time;
/** /**
* @param array $result * @param array $result
* @param integer $time * @param float $time
*/ */
public function __construct($result, $time = null) public function __construct($result, $time = null)
{ {
$this->result = $result; $this->result = $result;
$this->time = $time ?: time(); $this->time = $time ?: microtime(true);
} }
/** /**

View File

@ -35,6 +35,6 @@ class TimestampQueryCacheValidator implements QueryCacheValidator
return true; return true;
} }
return ($entry->time + $key->lifetime) > time(); return ($entry->time + $key->lifetime) > microtime(true);
} }
} }

View File

@ -386,7 +386,7 @@ class DefaultQueryCacheTest extends OrmTestCase
array('id'=>2, 'name' => 'Bar') array('id'=>2, 'name' => 'Bar')
); );
$entry->time = time() - 100; $entry->time = microtime(true) - 100;
$this->region->addReturn('get', $entry); $this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0])); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0]));