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

Added result caching for QueryBuilder #5539

Merged
merged 1 commit into from Jul 30, 2022
Merged

Conversation

twoleds
Copy link
Contributor

@twoleds twoleds commented Jul 26, 2022

Q A
Type improvement
Fixed issues

Summary

Added enable/disableResultCache method in QueryBuilder for result caching.

I use doctrine/dbal in several projects and the result caching is annoying. Only way I can use result caching is calling executeCacheQuery method in Connection. I cannot use fetch* methods in QueryBuilder.

I repeat this piece of code:

$builder = $connection->createQueryBuilder();
// ....
$result = $connection->executeCacheQuery(
    $builder->getSQL(),
    $builder->getParameters(),
    [],
    new \Doctrine\DBAL\Cache\QueryCacheProfile($cacheLifetime)
)->fetchAllAssociative();

With this improvement it will be:

$builder = $connection->createQueryBuilder();
// ....
$builder->enableResultCache(300)->fetchAllAssociative();

What do you think about it? Is it possible to implement something like that?

src/Connection.php Outdated Show resolved Hide resolved
@twoleds twoleds changed the title Added result caching for QueryBuilder and fetch/iterate methods in Connection Added result caching for QueryBuilder Jul 27, 2022
src/Query/QueryBuilder.php Outdated Show resolved Hide resolved
@morozov morozov changed the base branch from 3.3.x to 3.4.x July 27, 2022 14:58
@morozov
Copy link
Member

morozov commented Jul 27, 2022

@twoleds please rebase your branch on top of 3.4.x. The default 3.3.x branch accepts only bug fixes.

@twoleds twoleds force-pushed the result-caching branch 5 times, most recently from db3846c to b13f970 Compare July 28, 2022 10:50
@twoleds twoleds marked this pull request as ready for review July 28, 2022 10:51
morozov
morozov previously approved these changes Jul 28, 2022
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

Looks good. Good work @twoleds! I'll let the PR hang for a bit more in case anybody has feedback.

derrabus
derrabus previously approved these changes Jul 28, 2022
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Is there documentation to update?

@morozov
Copy link
Member

morozov commented Jul 28, 2022

Yeah, a section on caching could added to this document:

@twoleds
Copy link
Contributor Author

twoleds commented Jul 28, 2022

I provided some documentation for the query builder, but my English is not so good, please check it if I wrote it correct.

docs/en/reference/query-builder.rst Outdated Show resolved Hide resolved
docs/en/reference/query-builder.rst Outdated Show resolved Hide resolved
@twoleds twoleds force-pushed the result-caching branch 3 times, most recently from bb591f8 to 47574ed Compare July 29, 2022 08:11
src/Query/QueryBuilder.php Outdated Show resolved Hide resolved
@morozov morozov merged commit 4b75526 into doctrine:3.4.x Jul 30, 2022
@morozov
Copy link
Member

morozov commented Jul 30, 2022

Thanks, @twoleds!

@twoleds
Copy link
Contributor Author

twoleds commented Jul 31, 2022

Thanks for help to everyone, it was an interesting exprerience for me, I'm very happy that we have reached a successful end. Life will be a little bit easier. ❤️

@twoleds twoleds deleted the result-caching branch July 31, 2022 07:51
@rvanlaak
Copy link

rvanlaak commented Sep 23, 2022

This feature is so cool, thank you for your contribution @twoleds ! 👏

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants