You are here

function authcache_block_variables_gc in Authenticated User Page Caching (Authcache) 7.2

Garbage collect spurious variables.

1 call to authcache_block_variables_gc()
authcache_block_authcache_p13n_fragment in modules/authcache_block/authcache_block.module
Implements hook_authcache_p13n_fragment().

File

modules/authcache_block/authcache_block.module, line 142
Authcache support for block module.

Code

function authcache_block_variables_gc() {
  $result = db_select('block', 'b')
    ->fields('b')
    ->execute();
  $blocks = $result
    ->fetchAllAssoc('bid');
  $variable_whitelist = array();
  foreach ($blocks as $block) {
    $block_id = "{$block->module}-{$block->delta}";
    $config = variable_get('authcache_block-' . $block_id);
    if (!empty($config['status'])) {
      $variable_whitelist[] = 'authcache_block-' . $block_id;
    }
  }

  // Remove variables containing configuration of blocks where authcache has
  // been disabled. This also kills variables left over by custom blocks which
  // have been deleted. Note the variables are only cleared from the database
  // and still may linger in the variable cache until it is cleared the next
  // time.
  $query = db_delete('variable')
    ->condition('name', 'authcache_block-%', 'LIKE');
  if ($variable_whitelist) {
    $query
      ->condition('name', $variable_whitelist, 'NOT IN');
  }
  $query
    ->execute();
}