1
0
mirror of synced 2025-03-14 08:36:09 +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 5eebdcf630
commit 16a3a2a132
4 changed files with 12 additions and 6 deletions

@ -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

@ -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);
} }
/** /**

@ -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);
} }
} }

@ -436,7 +436,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]));