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

Cache null/empty returns for findOneBy #11584

Open
wants to merge 4 commits into
base: 3.3.x
Choose a base branch
from

Conversation

dciprian-petrisor
Copy link

On 'findOneBy' calls which return no an empty result set from the persister, null values are not cached.
This makes it so that repeat calls of 'findOneBy' with the same criteria, always hit the database.

The changes introduced in this commit make the AbstractEntityPersister cache the empty result set in the region, so that repeat calls do not hit the database again.

The existing mechanism to invalidate the query cache is sufficient; any persist/update performed to the region will invalidate it, exactly how it happens for non-empty result sets.

This is also more in-line with the way 'loadByCriteria' and 'loadAll' behave.

Fixes #11563

dciprian-petrisor and others added 3 commits August 23, 2024 23:04
On 'findOneBy' calls which return no an empty result set from the
persister, null values are not cached.
This makes it so that repeat calls of 'findOneBy' with the same
criteria, always hit the database.

The changes introduced in this commit make the AbstractEntityPersister
cache the empty result set in the region, so that repeat calls do not
hit the database again.

The existing mechanism to invalidate the query cache is sufficient; any
persist/update performed to the region will invalidate it, exactly how
it happens for non-empty result sets.

This is also more in-line with the way 'loadByCriteria' and 'loadAll'
behave.
@derrabus derrabus changed the base branch from 3.2.x to 3.3.x September 17, 2024 19:40
@dciprian-petrisor
Copy link
Author

Ill be adding/fixing tests here in the next few days

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Isn't this a BC break ?

Before, I could have

$result = $repository->findOne(['foo' => $foo]);
$result2 = $repository->findOne(['foo' => $foo]);

And getting result2 !== null because of concurrency and another process could have inserted the result in DB.

After this PR it will still return NULL. So I cannot check again my DB.

@petrisorciprian-vitals
Copy link

@VincentLanglet If a value is inserted in DB, the timestamp region is updated.
The findOneBy query uses the timestamp region, so the NULL cached value is no longer valid because the timestamp in the timestamp region is greater than the one in the cached NULL result.

It is no different than caching a value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caching null returns for findOneBy queries
4 participants