Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

lcobucci
Copy link
Member

@lcobucci lcobucci commented Sep 2, 2016

As far as I saw that's the default Hibernate behavior (https://vladmihalcea.com/2015/06/08/how-does-hibernate-query-cache-work/) to keep the query cache consistent.

I'm just not sure if that is the way to go, basically because of the change on the CachedEntityPersister interface (I didn't want to duplicate the logic that generates the timestamp key).

@lcobucci
Copy link
Member Author

lcobucci commented Sep 5, 2016

I had an idea to improve this PR a bit by moving the timestamp region check to the query cache validator but this also means moving the timestampKey to the QueryCacheKey.

I think it's a better solution, what's your opinion?

@guilhermeblanco
Copy link
Member

@lcobucci indeed that's a MUCH BETTER solution. If I understood your idea correctly, you'd eliminate the BC break by adding a new interface method.
This means it could potentially be part of 2.X series instead of 3.X only. =)

If you're willing to work on that, I'd appreciate.

@lcobucci
Copy link
Member Author

lcobucci commented Sep 6, 2016

@guilhermeblanco I really need this to be part of 2.X so I'm glad to help 😉

If I understood your idea correctly, you'd eliminate the BC break by adding a new interface method.

My idea basically is:

  1. Add timestampRegion to the TimestampQueryCacheValidator constructor
  2. Add timestampKey to the QueryCacheKey constructor
  3. Make TimestampQueryCacheValidator#isValid() also validate the timestamp using the region and the key

I couldn't see the BC break you said, can you please elaborate a bit more?

The biggest question here is: what'd be the best place to retrieve the timestampKey?
Passing it to the QueryCacheKey constructor means that we need to have it available also on the AbstractQuery#executeUsingQueryCache().

Moving those things to que validator also simplifies the AbstractEntityPersister#getHash() logic, since we don't need concatenate the $timestamp anymore (and we could also remove the unused timestampRegion from the persister).

/**
* @return \Doctrine\ORM\Cache\TimestampCacheKey
*/
public function getTimestampKey();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bc break, sadly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't know how to regenerate a timestamp key, if not retrieved from here.

@lcobucci
Copy link
Member Author

lcobucci commented Sep 7, 2016

Ow ofc. Do you think that the solution I explained is applicable?

@Ocramius
Copy link
Member

Ocramius commented Sep 7, 2016

@lcobucci moving more info to the QueryCacheKey seems good to me, since it's information that sticks together anyway. I don't have the full picture though, sorry.

@lcobucci
Copy link
Member Author

lcobucci commented Sep 7, 2016

@guilhermeblanco @Ocramius introduced a tiny duplication in order to remove the BC break. I think it should be ok to be merged on v2.X now.

Anything else?


private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry)
{
if ($key->timestampKey === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock states that it is never null: can you check that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock is a liar! Will fix that, thanks

@lcobucci
Copy link
Member Author

lcobucci commented Sep 8, 2016

@guilhermeblanco @Ocramius comments processed let me know if there's anything else preventing this to be merged and let's :shipit:

@@ -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
Copy link
Member

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?

Copy link
Member Author

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

Ocramius added a commit that referenced this pull request Sep 8, 2016
Ocramius added a commit that referenced this pull request Sep 8, 2016
Ocramius added a commit that referenced this pull request Sep 8, 2016
@Ocramius Ocramius self-assigned this Sep 8, 2016
@Ocramius Ocramius added this to the 2.5.5 milestone Sep 8, 2016
Ocramius added a commit that referenced this pull request Sep 8, 2016
@Ocramius Ocramius closed this in 009e947 Sep 8, 2016
@Ocramius
Copy link
Member

Ocramius commented Sep 8, 2016

This goes into 2.5.5! Thanks @lcobucci

master: 009e947
2.5: e16de70

@lcobucci lcobucci deleted the fix/l2c-querycache branch September 8, 2016 12:11
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
alexgurrola pushed a commit to Sitetheory-Archive/doctrine2 that referenced this pull request Apr 13, 2017
alexgurrola pushed a commit to Sitetheory-Archive/doctrine2 that referenced this pull request Apr 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants