function apc_handle_set in APC - Alternative PHP Cache 5
Same name and namespace in other branches
- 6 apc.inc \apc_handle_set()
Set data into apc cache. We have to keep track of the bins ourselves since apc doesn't have the concept of "bins". So we keep a lookup table hash to be able to clear a single bin via flush.
Parameters
$key: The key of the data to retrieve.
$bin: The bin/silo to look in.
File
- ./
apc.inc, line 116
Code
function apc_handle_set($key, $data, $expire = CACHE_PERMENANT, $bin = 'cache') {
global $apc_page_stats;
$apc_page_stats['set']++;
if (!empty($key) && !empty($data)) {
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, initialize table
if (empty($lookup)) {
$lookup = array();
}
// Get full key for storage and set it to 1 so we can keep track of the bin
$full_key = apc_handle_key($key, $bin);
$lookup[$full_key] = 1;
// Attempt to store full key and value
if (!apc_store($full_key, $data, $expire)) {
unset($lookup[$full_key]);
$return = FALSE;
}
else {
$return = TRUE;
}
}
// Resave the lookup table (even on failure)
apc_store('apc_lookup_' . $bin, $lookup);
apc_remove_lock($bin);
return $return;
}