private function writeFile($id, $value, $preWriteValueProcessor = null)
    {
        $filePath = $this->getPath($id);
        $dirname = dirname($filePath);
        if (!file_exists($dirname)) {
            mkdir($dirname, self::DEFAULT_MASK, true);
        }

        // we first open with 'c' in case the flock fails
        // 'w' would empty the file that someone else might be working on
        if (false !== ($fp = @fopen($filePath, 'c')) && true === flock($fp, LOCK_EX)) {

            // Runs the pre write callable.
            if (is_callable($preWriteValueProcessor)) {
                $value = call_user_func($preWriteValueProcessor, $id);
            }

            // We first need to truncate.
            ftruncate($fp, 0);
            $string = $this->getContent($id, $value);
            $success = fwrite($fp, $string);
            @flock($fp, LOCK_UN);
            @fclose($fp);
            if ($success) {
                // OPcache workaround
                if (function_exists('opcache_invalidate')) {
                    opcache_invalidate($filePath, true);
                }
            } else {
                common_Logger::w('Could not write '.$filePath);
            }

            return $success !== false;
        } else {
            common_Logger::w('Could not obtain lock on '.$filePath);

            return false;
        }
    }