DDC-1026: Doctrine Cache #1282

Closed
opened 2026-01-22 13:08:13 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 10, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user garfield-fr:

I find a problem with doctrine cache key.

It use a namespace and key to save the value and never use the namespace to get it.

I checked that on AbstractQuery::getResultCacheId().

AbstractCache::save -> use $this->_getNamespacedId($id)

Originally created by @doctrinebot on GitHub (Feb 10, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user garfield-fr: I find a problem with doctrine cache key. It use a namespace and key to save the value and never use the namespace to get it. I checked that on AbstractQuery::getResultCacheId(). AbstractCache::save -> use $this->_getNamespacedId($id)
admin added the Bug label 2026-01-22 13:08:13 +01:00
admin closed this issue 2026-01-22 13:08:13 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 12, 2011):

Comment created by @beberlei:

AbstractQuery::getResultCacheId() does not append the namespace. The Cache functions fetch() and contains() do.

@doctrinebot commented on GitHub (Feb 12, 2011): Comment created by @beberlei: AbstractQuery::getResultCacheId() does not append the namespace. The Cache functions fetch() and contains() do.
Author
Owner

@doctrinebot commented on GitHub (Feb 13, 2011):

Comment created by garfield-fr:

This is my test project with Symfony2.
Load vendor with "git submodule update"

Thanks

@doctrinebot commented on GitHub (Feb 13, 2011): Comment created by garfield-fr: This is my test project with Symfony2. Load vendor with "git submodule update" Thanks
Author
Owner

@doctrinebot commented on GitHub (Feb 13, 2011):

Comment created by garfield-fr:

First query (no data on apc cache): http://www.screencast.com/t/kMZ4SSeORH and second (data on apc cache): http://screencast.com/t/uBO42F21

@doctrinebot commented on GitHub (Feb 13, 2011): Comment created by garfield-fr: First query (no data on apc cache): http://www.screencast.com/t/kMZ4SSeORH and second (data on apc cache): http://screencast.com/t/uBO42F21
Author
Owner

@doctrinebot commented on GitHub (Feb 13, 2011):

Comment created by garfield-fr:

I find the problem with cache. On function execute in AbstractQuery.php, if the cache is not an array, the return failed. In my result, i have only a string.
I have changed return $cached[$id]; with return is_array($cached) ? $cached[$id] : cached;

@doctrinebot commented on GitHub (Feb 13, 2011): Comment created by garfield-fr: I find the problem with cache. On function execute in AbstractQuery.php, if the cache is not an array, the return failed. In my result, i have only a string. I have changed return $cached[$id]; with return is_array($cached) ? $cached[$id] : cached;
Author
Owner

@doctrinebot commented on GitHub (Feb 24, 2011):

Comment created by awoods:

Actually, I think ALL result caching may be broken since the fix for DDC-892 landed. The code is expecting to fetch an array from the cache with an element in it thats key is $id. Presumably, this is to cater for cases where the hash clashes for different ids. However, the query result is not being inserted into the cache in this format!

This patch should fix the issue.

There's still a less serious issue - and that's that if there are two ids with clashing hashes that are being called repeatedly in quick succession, they're going to keep displacing each other from the cache. An alternative patch could bundle both ids them into the same cache entry:

if ($cached === false)
$cached = array();
$cached[$id] = $result;
$cacheDriver->save($id, $cached, $this->_resultCacheTTL);

However, I think displacing is better than running the risk of having a TTL that is too long be applied as the result of a clash!

EDIT: I'm also wondering why $hash isn't used as the cache key. It looks like the intention was that it should be, but it isn't..

@doctrinebot commented on GitHub (Feb 24, 2011): Comment created by awoods: Actually, I think ALL result caching may be broken since the fix for [DDC-892](http://www.doctrine-project.org/jira/browse/DDC-892) landed. The code is expecting to fetch an array from the cache with an element in it thats key is $id. Presumably, this is to cater for cases where the hash clashes for different ids. However, the query result is not being inserted into the cache in this format! This patch should fix the issue. There's still a less serious issue - and that's that if there are two ids with clashing hashes that are being called repeatedly in quick succession, they're going to keep displacing each other from the cache. An alternative patch could bundle both ids them into the same cache entry: if ($cached === false) $cached = array(); $cached[$id] = $result; $cacheDriver->save($id, $cached, $this->_resultCacheTTL); However, I think displacing is better than running the risk of having a TTL that is too long be applied as the result of a clash! EDIT: I'm also wondering why $hash isn't used as the cache key. It looks like the intention was that it should be, but it isn't..
Author
Owner

@doctrinebot commented on GitHub (Feb 25, 2011):

Comment created by @beberlei:

Fixed, the DDC-892 patch was pretty borked. This does now work

@doctrinebot commented on GitHub (Feb 25, 2011): Comment created by @beberlei: Fixed, the [DDC-892](http://www.doctrine-project.org/jira/browse/DDC-892) patch was pretty borked. This does now work
Author
Owner

@doctrinebot commented on GitHub (Feb 25, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 25, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 2 attachments from Jira into https://gist.github.com/59eae5816b95e80c24a9

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 2 attachments from Jira into https://gist.github.com/59eae5816b95e80c24a9 - [10939_AbstractQuery.php.patch](https://gist.github.com/59eae5816b95e80c24a9#file-10939_AbstractQuery-php-patch) - [10944_yay-caching-works-again.patch](https://gist.github.com/59eae5816b95e80c24a9#file-10944_yay-caching-works-again-patch)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1282