I'm trying to create middleware which will check status of specified server and put this status to the Cache, but the cache is not working in middleware properly, given cache value is always null when I'm trying to check the key existence etc.
public function handle($request, Closure $next)
{
$response = $next($request);
if(!Cache::has(Config::get('ots.server_status_cache_name'))) {
if($this->checkServerStatus()) {
Cache::put(Config::get('ots.server_status_cache_name'), 1, Config::get('ots.server_status_cache_time'));
} else {
Cache::put(Config::get('ots.server_status_cache_name'), 0, Config::get('ots.server_status_cache_time'));
}
}
return $response;
}
Just for your know, $this->checkServerStatus() returns true/false.
So, when I'm trying to check Cache key existance, it's always false for Cache::has("KEY") or null for Cache::get("KEY").
What's wrong? I cannot use cache in Middleware?