lithium\storage\cache\adapter\File::_read()

protected method

Reads from file, parses its format and returns its expiry and value.

Parameters

  • string $key

    Key to uniquely identify the cached item.

  • boolean $streams

    When true will return stream handle instead of value.

Returns

array|boolean

Array with expiry and value or false otherwise.

Source

	protected function _read($key, $streams = false) {
		$path = "{$this->_config['path']}/{$key}";

		if (!is_file($path) || !is_readable($path)) {
			return false;
		}
		if (!$stream = fopen($path, 'rb')) {
			return false;
		}
		$header = stream_get_line($stream, static::MAX_HEADER_LENGTH, "\n");

		if (!preg_match('/^\{\:expiry\:(\d+)\}/', $header, $matches)) {
			return false;
		}
		if ($streams) {
			$value = fopen('php://temp', 'wb');
			stream_copy_to_stream($stream, $value);
			rewind($value);
		} else {
			$value = stream_get_contents($stream);
		}
		fclose($stream);

		return ['expiry' => $matches[1], 'value' => $value];

	}