-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make query cache rely on entity timestamp region #6001
Changes from all commits
9df3dd2
fd15d7d
2a320f2
9130d8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,14 +45,27 @@ class QueryCacheKey extends CacheKey | |
public $cacheMode; | ||
|
||
/** | ||
* @param string $hash Result cache id | ||
* @param integer $lifetime Query lifetime | ||
* @param integer $cacheMode Query cache mode | ||
* READ-ONLY: Public only for performance reasons, it should be considered immutable. | ||
* | ||
* @var TimestampCacheKey|null | ||
*/ | ||
public $timestampKey; | ||
|
||
/** | ||
* @param string $hash Result cache id | ||
* @param integer $lifetime Query lifetime | ||
* @param int $cacheMode Query cache mode | ||
* @param TimestampCacheKey|null $timestampKey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically because of https://github.com/doctrine/doctrine2/blob/8a87fa2d01a01f4ae939559b10cb5733132930cf/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php#L1106 and https://github.com/doctrine/doctrine2/blob/8a87fa2d01a01f4ae939559b10cb5733132930cf/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php#L1117 Since the ResultSetMapping don't give the entity name. |
||
*/ | ||
public function __construct($hash, $lifetime = 0, $cacheMode = Cache::MODE_NORMAL) | ||
{ | ||
$this->hash = $hash; | ||
$this->lifetime = $lifetime; | ||
$this->cacheMode = $cacheMode; | ||
public function __construct( | ||
$hash, | ||
$lifetime = 0, | ||
$cacheMode = Cache::MODE_NORMAL, | ||
TimestampCacheKey $timestampKey = null | ||
) { | ||
$this->hash = $hash; | ||
$this->lifetime = $lifetime; | ||
$this->cacheMode = $cacheMode; | ||
$this->timestampKey = $timestampKey; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,49 @@ | |
*/ | ||
class TimestampQueryCacheValidator implements QueryCacheValidator | ||
{ | ||
/** | ||
* @var TimestampRegion | ||
*/ | ||
private $timestampRegion; | ||
|
||
/** | ||
* @param TimestampRegion $timestampRegion | ||
*/ | ||
public function __construct(TimestampRegion $timestampRegion) | ||
{ | ||
$this->timestampRegion = $timestampRegion; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isValid(QueryCacheKey $key, QueryCacheEntry $entry) | ||
{ | ||
if ($this->regionUpdated($key, $entry)) { | ||
return false; | ||
} | ||
|
||
if ($key->lifetime == 0) { | ||
return true; | ||
} | ||
|
||
return ($entry->time + $key->lifetime) > time(); | ||
return ($entry->time + $key->lifetime) > microtime(true); | ||
} | ||
|
||
/** | ||
* @param QueryCacheKey $key | ||
* @param QueryCacheEntry $entry | ||
* | ||
* @return bool | ||
*/ | ||
private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docblock plz, even if it just says that a boolean is returned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😉 |
||
{ | ||
if ($key->timestampKey === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docblock states that it is never There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docblock is a liar! Will fix that, thanks |
||
return false; | ||
} | ||
|
||
$timestamp = $this->timestampRegion->get($key->timestampKey); | ||
|
||
return $timestamp && $timestamp->time > $entry->time; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there was a change here, did you check all usages of this property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did but I definitely forgot to change
($entry->time + $key->lifetime) > time()
to((int) $entry->time + $key->lifetime) > time()
on the validator