Problem/Motivation
It looks like the current cache clearing implementation in EntityCacheControllerHelper::resetEntityCache() is wrong. This could lead to unexpected behaviour if an explicit cache clear is requested.
The current code looks like this:
// Reset the persistent cache.
if (isset($ids)) {
cache_clear_all($ids, 'cache_entity_' . $controller->entityType);
}
If I understand that right the cache_clear_all is called only if $ids is set (and is not NULL).
According to DrupalEntityControllerInterface::resetCache() $ids can be NULL and in such case the whole cache has to be cleared.
This means EntityCacheControllerHelper::resetEntityCache() misses a handling for the case $ids is NULL.
Further cache_clear_all() doesn't seem to support an array as $cid - this means passing the $ids as parameter for $cid won't lead to the expected behaviour.
Proposed resolution
- Add iteration over
$idsto callcache_clear_all()- similar approach as this, never comitted one, here: #1050562: Does not support $reset argument - Add handling for the case
$idsis NULL. I'm not sure yet what to use:cache_clear_all(NULL, 'cache_entity_' . $controller->entityType);- deletes only expired items.cache_clear_all('*', 'cache_entity_' . $controller->entityType, TRUE);- deletes all items and seems to work better, but that can be caused by the fact I used memcache to test this.
Remaining tasks
Review patch.
Decide which cache_clear_all() call should be used in the "$ids is NULL" case.
User interface changes
none
API changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entitycache-fix-possible-issue-with-resetEntityCache.patch-1333542-2.patch | 1.13 KB | das-peter |
| fix-possible-issue-with-resetEntityCache.patch | 1.24 KB | das-peter |
Comments
Comment #1
catchcache_clear_all() accepts $cids as an array in D7.
However otherwise this looks good - should definitely be '*' and not NULL passed to cache_clear_all().
Comment #2
das-peter commentedThanks for the feedback.
I must have missed somehow that arrays are accepted :|
However, here's the adjusted patch which checks if
$idsis empty and takes the appropriate action.Comment #3
catchThanks! Committed/pushed to 7.x-1.x
Comment #5
j0rd commentedJust encountered this causing problems with ApacheSolr module, which clears the cache via a node_load($nid, NULL, TRUE); I'm sure this functionality node_load with cache reset is used quite frequently in contrib and if someone has entitycache enabled, it will not work and cause problems.
Would it be possible to rollout a new release with this fix. It's been a while and I think this could be causing issues for people who don't know it.
Comment #6
erikwebb commented#1049124: node_load() with $reset = TRUE needs some tweaking