* @param mixed * @return void */ public static function scheduleCacheWrite($k, &$v) { if (!self::$hasSchCacheTrig) { register_shutdown_function(array('SVN', 'finalize')); self::$hasSchCacheTrig = true; } self::$scheduledCacheWrites[$k] =& $v; } /** @ignore */ public static function finalize() { foreach (self::$scheduledCacheWrites as $k => $v) { $tmpfile = '/tmp/' . $k . '.lock'; if (!($fp = fopen($tmpfile, 'w'))) { throw new IOException("Failed to create lock file '{$tmpfile}'"); } flock($fp, LOCK_EX); # check AGAIN after we get the lock. Maybe someone was faster than us... if (apc_fetch($k) === false) { apc_store($k, $v, SVN::$apcTTL); } fclose($fp); @unlink($tmpfile); } } } SVN::$apcEnabled = function_exists('apc_fetch');