You are here

function views_content_cache_update_get in Views content cache 7.3

Same name and namespace in other branches
  1. 6.2 views_content_cache.module \views_content_cache_update_get()

Retrieve the latest update record for a given cache id.

Parameters

array $cid: A cache id array. May contain multiple values for each key id.

boolean $reset: Reset the internal static cache of timestamps for particular keys.

Return value

int Returns the timestamp of the latest update record matching the given cache id or FALSE if none was found.

3 calls to views_content_cache_update_get()
ViewsContentCacheTest::testarticleContentAdded in tests/views_content_cache.test
Test that when a node is added the appropriate cache segment is updated.
ViewsContentCacheTest::testCommentAdded in tests/views_content_cache.test
Test that when a comment is added to a article the timestamp is recorded.
views_content_cache_plugin_cache::cache_expire in views/views_content_cache_plugin_cache.inc
Return the expiry time for this cache plugin.

File

./views_content_cache.module, line 147
Views content cache cache.

Code

function views_content_cache_update_get($cid, $reset = FALSE) {
  static $cache = array();
  $hash = md5(serialize($cid));
  if (!isset($cache[$hash]) || $reset) {
    $mapped = views_content_cache_id_record($cid);

    // Generate the where clause from the cache id.
    $where_query = array(
      '#glue' => 'OR',
      array(
        '#glue' => 'AND',
      ),
    );
    foreach ($mapped as $key_id => $key_value) {
      if (!empty($key_value)) {

        // Use a simpler syntax for single value wheres:
        if (count($key_value) == 1) {
          $where = "{$key_id} = :{$key_id}";
        }
        else {
          $where = "{$key_id} IN (:{$key_id})";
        }

        // Work out where the clause should be put in the query array:
        if ('AND' == views_content_cache_and_or_key_get($key_id)) {

          // AND queries go to a sub array of the clause:
          $where_query[0][] = array(
            '#clause' => $where,
            '#args' => array(
              ":{$key_id}" => array_values($key_value),
            ),
          );
        }
        else {

          // OR queries go to the base clause:
          $where_query[] = array(
            '#clause' => $where,
            '#args' => array(
              ":{$key_id}" => array_values($key_value),
            ),
          );
        }
      }
    }
    $built_clause = views_content_cache_query_builder($where_query);

    // If there were arguments in the query, run it.
    if (!empty($built_clause['#args'])) {
      $cache[$hash] = db_query("SELECT timestamp FROM {views_content_cache} WHERE " . $built_clause['#clause'] . " ORDER BY timestamp DESC", $built_clause['#args'])
        ->fetchField();
    }
    else {
      $cache[$hash] = FALSE;
    }
  }
  return $cache[$hash];
}