-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e2df72
commit 457e056
Showing
7 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Statamic\Http\Middleware; | ||
|
||
use Closure; | ||
use Statamic\Facades\Stache; | ||
|
||
class StacheLock | ||
{ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (! config('statamic.stache.lock.enabled', true)) { | ||
return $next($request); | ||
} | ||
|
||
$start = time(); | ||
$lock = Stache::lock('stache-warming'); | ||
|
||
while (! $lock->acquire()) { | ||
if (time() - $start >= config('statamic.stache.lock.timeout', 30)) { | ||
return $this->outputRefreshResponse($request); | ||
} | ||
|
||
sleep(1); | ||
} | ||
|
||
$lock->release(); | ||
|
||
return $next($request); | ||
} | ||
|
||
private function outputRefreshResponse($request) | ||
{ | ||
$html = $request->ajax() || $request->wantsJson() | ||
? __('Service Unavailable') | ||
: sprintf('<meta http-equiv="refresh" content="1; URL=\'%s\'" />', $request->getUri()); | ||
|
||
return response($html, 503, ['Retry-After' => 1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Statamic\Stache; | ||
|
||
use Symfony\Component\Lock\BlockingStoreInterface; | ||
use Symfony\Component\Lock\Key; | ||
|
||
class NullLockStore implements BlockingStoreInterface | ||
{ | ||
public function save(Key $key) | ||
{ | ||
// | ||
} | ||
|
||
public function delete(Key $key) | ||
{ | ||
// | ||
} | ||
|
||
public function exists(Key $key) | ||
{ | ||
// | ||
} | ||
|
||
public function putOffExpiration(Key $key, float $ttl) | ||
{ | ||
// | ||
} | ||
|
||
public function waitAndSave(Key $key) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters