PhpFileCache with Query #6495

Open
opened 2026-01-22 15:34:06 +01:00 by admin · 2 comments
Owner

Originally created by @vv12131415 on GitHub (Jun 26, 2020).

Q A
Version 2.6.x

Support Question

As it says at the documentation, https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/caching.html#phpfilecache it is perfect fit to set PhpFileCache as a cache driver for metadata and query.

For metadata it works perfectly, but for query cache (not the result) I see weird behaviour, it just writes to cache and doesn't read from it. That's becauselifetime that is passed to PhpFileCache::save is ALWAYS null.

I've debugged the save method and found where the cache lifetime is set.
And I looked at this property _queryCacheTTL.
4fae126459/lib/Doctrine/ORM/Query.php (L192) (which is actually null, not int). Null for cache lifetime means that we cache the result, but when we check it again, it is empty, so we are always writing to cache.

Am I doing/configuring something wrong?
Is _queryCacheTTL set to null on purpose?

Originally created by @vv12131415 on GitHub (Jun 26, 2020). <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ----- | Version | 2.6.x <!-- Before asking question here, please try asking on Gitter or Slack first. Find out more about Doctrine support channels here: https://www.doctrine-project.org/community/ Keep in mind that GitHub is primarily an issue tracker. --> ### Support Question As it says at the documentation, https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/caching.html#phpfilecache it is perfect fit to set `PhpFileCache` as a cache driver for metadata and query. For metadata it works perfectly, but for query cache (not the result) I see weird behaviour, it just writes to cache and doesn't read from it. That's because`lifetime` that is passed to `PhpFileCache::save` is ALWAYS `null`. I've debugged the save method and found where the cache lifetime is set. And I looked at this property `_queryCacheTTL`. https://github.com/doctrine/orm/blob/4fae126459d7deb6cb2877fc0c0f8ecfa4658516/lib/Doctrine/ORM/Query.php#L192 (which is actually null, not int). Null for cache lifetime means that we cache the result, but when we check it again, it is empty, so we are always writing to cache. Am I doing/configuring something wrong? Is `_queryCacheTTL` set to `null` on purpose?
Author
Owner

@Philosoft commented on GitHub (Jan 29, 2021):

If your previous research was right, than there is no way to fix it from configuration perspective, since _queryCacheTTL is changing only in 1 place

4fae126459/lib/Doctrine/ORM/Query.php (L507-L523)

which is never ever called. But is used in

1 test
5801474ba3/tests/Doctrine/Tests/ORM/Query/QueryTest.php (L95-L99)

and 1 documentation line 3ef5a30102/docs/en/reference/dql-doctrine-query-language.rst (query-cache-dql-query-only)

so as far as I understand the only option to fix it is to modify every query with ->setQueryCacheLifetime(0)

@Philosoft commented on GitHub (Jan 29, 2021): If your previous research was right, than there is no way to fix it from configuration perspective, since `_queryCacheTTL` is changing only in 1 place https://github.com/doctrine/orm/blob/4fae126459d7deb6cb2877fc0c0f8ecfa4658516/lib/Doctrine/ORM/Query.php#L507-L523 which is never ever called. But is used in 1 test https://github.com/doctrine/orm/blob/5801474ba32799b4676041a785b987be0043b3fe/tests/Doctrine/Tests/ORM/Query/QueryTest.php#L95-L99 and 1 documentation line https://github.com/doctrine/orm/blob/3ef5a30102905483c29a6849c8c4efb4dfbe97d6/docs/en/reference/dql-doctrine-query-language.rst#query-cache-dql-query-only so as far as I understand the only option to fix it is to modify every query with `->setQueryCacheLifetime(0)`
Author
Owner

@JindrichPilar commented on GitHub (Mar 4, 2021):

I encountered this problem too on 2.7.5 and came to the same conclusion as @vladyslavstartsev.

null as TTL means expire never in RedisCache, but expire immediatelly in PhpFileCache.

In my opininion this is bug in doctrine/orm, because it passes null to a method argument that accepts only integer

Setting default value of $_queryCacheTTL to 0 should fix this. In fact it already has phpdoc @var int, yet it contains null.

From quick look at 2.8.x it seem the problem is there too, although property is no longer prefixed with underscore.

@JindrichPilar commented on GitHub (Mar 4, 2021): I encountered this problem too on 2.7.5 and came to the same conclusion as @vladyslavstartsev. `null` as TTL means expire never in [RedisCache](https://github.com/doctrine/cache/blob/1.10.x/lib/Doctrine/Common/Cache/RedisCache.php#L122), but expire immediatelly in [PhpFileCache](https://github.com/doctrine/cache/blob/1.10.x/lib/Doctrine/Common/Cache/PhpFileCache.php#L112). In my opininion this is bug in `doctrine/orm`, because it passes `null` to a method argument that [accepts only `integer`](https://github.com/doctrine/cache/blob/1.10.x/lib/Doctrine/Common/Cache/Cache.php#L49) Setting default value of `$_queryCacheTTL` to `0` should fix this. In fact it already has phpdoc `@var int`, yet it contains null. From quick look at 2.8.x it seem the problem is there too, although property is no longer prefixed with underscore.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6495