protected function doGet($key)
{
$path = $this->getPath($key);
if (!file_exists($path)) {
return false;
}
$h = fopen($path, 'r');
$maxTries = 400;
//wait max. 2 seconds, otherwise force it
$tries = 0;
while (!flock($h, LOCK_SH) and $tries <= $maxTries) {
usleep(1000 * 5);
//5ms
$tries++;
}
if ($this->useJson) {
$value = '';
while (!feof($h)) {
$value .= fread($h, 8192);
}
} else {
$value = (include $path);
}
flock($h, LOCK_UN);
fclose($h);
if ($this->useJson) {
return json_decode($value, true);
} else {
return $value;
}
}