You are here

function apc_handle_flush in APC - Alternative PHP Cache 5

Same name and namespace in other branches
  1. 6 apc.inc \apc_handle_flush()

Flush data from apc cache

Parameters

$key: The key of the data to retrieve.

$bin: The bin/silo to look in.

1 call to apc_handle_flush()
cache_clear_all in ./apc.inc

File

./apc.inc, line 187

Code

function apc_handle_flush($bin = 'cache') {
  if (!apc_get_lock($bin)) {
    watchdog('apc', 'Unable to get lock for bin: ' . $bin, WATCHDOG_ERROR);
    return FALSE;
  }

  // Get lookup table to be able to keep track of bins
  $lookup = apc_fetch('apc_lookup_' . $bin);

  // If the lookup table is empty, remove lock and return
  if (empty($lookup)) {
    apc_remove_lock($bin);
    return TRUE;
  }

  // Cycle through keys and remove each entry from the cache
  foreach ($lookup as $key => $val) {
    if (!apc_delete($key)) {
      watchdog('apc', "Unable to remove {$key} from {$bin}");
    }
    else {
      unset($lookup[$key]);
    }
  }

  // Resave the lookup table (even on failure)
  apc_store('apc_lookup_' . $bin, $lookup);

  // Remove lock
  apc_remove_lock($bin);
  return TRUE;
}