You are here

function media_acquiadam_cache_get_multiple in Media: Acquia DAM 7

Retrieve multiple assets from the cache.

Parameters

array $assetIds: An array of asset IDs to fetch from cache.

Return value

array The array of asset data from cache, keyed by ID.

1 call to media_acquiadam_cache_get_multiple()
media_acquiadam_cache_get in includes/media_acquiadam.cache.inc
Get locally cached Acquia DAM asset information.

File

includes/media_acquiadam.cache.inc, line 73
Cache helpers and associated logic.

Code

function media_acquiadam_cache_get_multiple(array $assetIds) {
  $query = db_select('acquiadam_asset_cache', 'c')
    ->addTag('acquiadam')
    ->addTag('damcache')
    ->fields('c', [
    'data',
    'asset_id',
    'type',
  ])
    ->condition('c.asset_id', $assetIds)
    ->condition(db_or()
    ->condition('c.expiration', REQUEST_TIME, '>')
    ->isNull('c.expiration'))
    ->range(0, count($assetIds))
    ->orderBy('c.asset_id', 'ASC');
  $cache_expiration = variable_get('media_acquiadam_cache_expiration');
  if (!empty($cache_expiration)) {
    $query
      ->where('(c.changed + :cache_expiration) > :request_time', [
      ':cache_expiration' => $cache_expiration * 60 * 1000,
      ':request_time' => REQUEST_TIME,
    ]);
  }
  $result = $query
    ->execute()
    ->fetchAllAssoc('asset_id');
  if (!empty($result)) {
    array_walk($result, function (&$item, $key) {
      $item->data = unserialize($item->data);
    });
  }
  return $result;
}