DrupalAPCCache::prepareItem() uses $user->cache to verify the data is valid for the currently logged-in user

Created on 15 July 2024, 4 months ago
Updated 30 July 2024, 4 months ago

DrupalApcCache::prepareItem() uses $user->cache to verify the data is valid for the currently logged-in user, but Drupal core stopped to set $user->cache since at least May, 2012, as reported in the Drupal 7 CHANGELOG.txt file.

Drupal 7.14, 2012-05-02
-----------------------
- Fixed "integrity constraint" fatal errors when rebuilding registry.
- Fixed custom logo and favicon functionality referencing incorrect paths.
- Fixed DB Case Sensitivity: Allow BINARY attribute in MySQL.
- Split field_bundle_settings out per bundle.
- Improve UX for machine names for fields (UI change).
- Fixed User pictures are not removed properly.
- Fixed HTTPS sessions not working in all cases.
- Fixed Regression: Required radios throw illegal choice error when none selected.
- Fixed allow autocompletion requests to include slashes.
- Eliminate $user->cache and {session}.cache in favor of $_SESSION['cache_expiration'][$bin] (Performance).

 

The used code should be similar to the one used by DrupalDatabaseCache::prepareItem(),

if (!isset($cache->data)) {
  return FALSE;
}
// If the cached data is temporary and subject to a per-user minimum
// lifetime, compare the cache entry timestamp with the user session
// cache_expiration timestamp. If the cache entry is too old, ignore it.
if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && isset($_SESSION['cache_expiration'][$this->bin]) && $_SESSION['cache_expiration'][$this->bin] > $cache->created) {
  // Ignore cache data that is too old and thus not valid for this user.
  return FALSE;
}

// If the data is permanent or not subject to a minimum cache lifetime,
// unserialize and return the cached data.
if ($cache->serialized) {
  $cache->data = unserialize($cache->data);
}

return $cache;
🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇹Italy apaderno Brescia, 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024