cache_get_multiple() is supposed to take $cids by reference and mutate the array to remove found keys. We're not doing this at the moment, meaning a lot of code (notably all of Ctools) things we're missing the cache all the time.

https://api.drupal.org/api/drupal/includes%21cache.inc/function/cache_ge...

I solved this by adding an array_diff() as seen in the default DrupalDatabaseCache implementation, adding it to LCache's getMultiple() method:

  public function getMultiple(&$cids) {
    if (empty($cids)) return;
    $cache = array();
    foreach ($cids as $cid) {
      $c = $this->get($cid);
      if (!empty($c)) {
        $cache[$cid] = $c;
      }
    }
    $cids = array_diff($cids, array_keys($cache));
    return $cache;
  }

Comments

joshk created an issue. See original summary.

joshk’s picture

Title: MultiGet needs to mutate &$cids properly » MultiGet() needs to mutate &$cids properly
david strauss’s picture

Priority: Normal » Major

Bumping to "major" because this substantially hurts performance, which is the whole point of running this project. ;-)

  • David Strauss committed c78793e on 7.x-1.x
    Issue #2808971: getMultiple should remove found keys from $cid
    
david strauss’s picture

Assigned: Unassigned » david strauss
Status: Active » Fixed
david strauss’s picture

Status: Fixed » Closed (fixed)