/**
  * @param array $cached
  * @param array $keyToQuery
  * @return ResultDuplicator
  */
 public function getResultDuplicator(array $cached, array $keyToQuery)
 {
     $results = $this->inner->expandCacheResult($cached, $keyToQuery);
     // Allows us to flatten $results into a single $query array, then
     // rebuild final return value in same structure and order as $results.
     $duplicator = new ResultDuplicator($this->shallow->getPrimaryKeyColumns(), 2);
     foreach ($results as $i => $rows) {
         foreach ($rows as $j => $row) {
             $duplicator->add($row, array($i, $j));
         }
     }
     return $duplicator;
 }
 /**
  * Returns a boolean true/false if the findMulti()-operation for the given
  * attributes has already been resolves and doesn't need to query any
  * outside cache/database.
  * Determining if a find() has not yet been resolved may be useful so that
  * additional data may be loaded at once.
  *
  * @param array $queries Queries to findMulti()
  * @param array[optional] $options Options to findMulti()
  * @return bool
  */
 public function foundMulti(array $queries, array $options = array())
 {
     if (!$queries) {
         return true;
     }
     // get cache keys for all queries
     $cacheKeys = $this->getCacheKeys($queries);
     // check if cache has a way of identifying what's stored locally
     if (!method_exists($this->cache, 'has')) {
         return false;
     }
     // check if keys matching given queries are already known in local cache
     foreach ($cacheKeys as $key) {
         if (!$this->cache->has($key)) {
             return false;
         }
     }
     $keyToQuery = array();
     foreach ($cacheKeys as $i => $key) {
         // These results will be merged into the query results, and as such need binary
         // uuid's as would be received from storage
         if (!isset($keyToQuery[$key])) {
             $keyToQuery[$key] = $queries[$i];
         }
     }
     // retrieve from cache - this is cheap, it's is local storage
     $cached = $this->cache->getMulti($cacheKeys);
     foreach ($cached as $i => $result) {
         $limit = isset($options['limit']) ? $options['limit'] : $this->getLimit();
         $cached[$i] = array_splice($result, 0, $limit);
     }
     // if we have a shallow compactor, the returned data are PKs of objects
     // that need to be fetched too
     if ($this->rowCompactor instanceof ShallowCompactor) {
         // test of the keys to be expanded are already in local cache
         $duplicator = $this->rowCompactor->getResultDuplicator($cached, $keyToQuery);
         $queries = $duplicator->getUniqueQueries();
         if (!$this->rowCompactor->getShallow()->foundMulti($queries)) {
             return false;
         }
     }
     return true;
 }