mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
Merge pull request #247 from lbryio/clear-cache
Add route to clear cache
This commit is contained in:
commit
e9df217483
6 changed files with 35 additions and 8 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
class Controller
|
||||
{
|
||||
const CACHE_CLEAR_PATH = '/clear-cache';
|
||||
|
||||
protected static $queuedFunctions = [];
|
||||
|
||||
public static function dispatch($uri)
|
||||
|
@ -109,6 +111,7 @@ class Controller
|
|||
|
||||
$router->post('/postcommit', 'OpsActions::executePostCommit');
|
||||
$router->post('/log-upload', 'OpsActions::executeLogUpload');
|
||||
$router->get(static::CACHE_CLEAR_PATH, 'OpsActions::executeClearCache');
|
||||
|
||||
$router->any('/list/subscribe', 'MailActions::executeSubscribe');
|
||||
$router->any('/list/subscribed', 'MailActions::executeSubscribed');
|
||||
|
|
|
@ -2,6 +2,20 @@
|
|||
|
||||
class OpsActions extends Actions
|
||||
{
|
||||
public static function executeClearCache(): array
|
||||
{
|
||||
if (!ini_get('apc.enabled') || !function_exists('apc_clear_cache'))
|
||||
{
|
||||
return View::renderJson(['success' => false, 'error' => 'Cache not enabled']);
|
||||
}
|
||||
|
||||
apc_clear_cache();
|
||||
apc_clear_cache('user');
|
||||
apc_clear_cache('opcode');
|
||||
|
||||
return View::renderJson(['success' => true]);
|
||||
}
|
||||
|
||||
public static function executePostCommit(): array
|
||||
{
|
||||
$payload = Request::getParam('payload');
|
||||
|
|
|
@ -21,3 +21,6 @@ Shell::exec('git fetch && git reset --hard origin/master');
|
|||
|
||||
View::compileCss();
|
||||
View::gzipAssets();
|
||||
|
||||
// clear cache
|
||||
Curl::get('localhost'.Controller::CACHE_CLEAR_PATH);
|
|
@ -352,7 +352,7 @@ class Response
|
|||
return $statusTexts[$code] ?? null;
|
||||
}
|
||||
|
||||
protected static function normalizeHeaderName($name)
|
||||
protected static function normalizeHeaderName($name): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\-(.)/',
|
||||
|
|
|
@ -19,7 +19,7 @@ class View
|
|||
const CSS_DIR = self::WEB_DIR . '/css';
|
||||
const JS_DIR = self::WEB_DIR . '/js';
|
||||
|
||||
public static function render($template, array $vars = [])
|
||||
public static function render($template, array $vars = []): string
|
||||
{
|
||||
if (static::isMarkdown($template))
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ class View
|
|||
}
|
||||
}
|
||||
|
||||
public static function markdownToHtml($path)
|
||||
public static function markdownToHtml($path): string
|
||||
{
|
||||
return ParsedownExtra::instance()->text(trim(file_get_contents($path)));
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class View
|
|||
}
|
||||
}
|
||||
|
||||
protected static function interpolateTokens($html)
|
||||
protected static function interpolateTokens($html): string
|
||||
{
|
||||
return preg_replace_callback('/{{[\w\.]+}}/is', function ($m)
|
||||
{
|
||||
|
@ -162,12 +162,12 @@ class View
|
|||
}, $html);
|
||||
}
|
||||
|
||||
protected static function escapeOnce($value)
|
||||
protected static function escapeOnce($value): string
|
||||
{
|
||||
return preg_replace('/&([a-z]+|(#\d+)|(#x[\da-f]+));/i', '&$1;', htmlspecialchars((string)$value, ENT_QUOTES, 'utf-8'));
|
||||
}
|
||||
|
||||
protected static function attributesToHtml($attributes)
|
||||
protected static function attributesToHtml($attributes): string
|
||||
{
|
||||
return implode('', array_map(function ($k, $v)
|
||||
{
|
||||
|
@ -175,13 +175,19 @@ class View
|
|||
}, array_keys($attributes), array_values($attributes)));
|
||||
}
|
||||
|
||||
public static function renderTag($tag, $attributes = [])
|
||||
public static function renderTag($tag, $attributes = []): string
|
||||
{
|
||||
return $tag ? sprintf('<%s%s />', $tag, static::attributesToHtml($attributes)) : '';
|
||||
}
|
||||
|
||||
public static function renderContentTag($tag, $content = null, $attributes = [])
|
||||
public static function renderContentTag($tag, $content = null, $attributes = []): string
|
||||
{
|
||||
return $tag ? sprintf('<%s%s>%s</%s>', $tag, static::attributesToHtml($attributes), $content, $tag) : '';
|
||||
}
|
||||
|
||||
public static function renderJson($data): array
|
||||
{
|
||||
Response::setHeader(Response::HEADER_CONTENT_TYPE, 'application/json');
|
||||
return ['internal/json', ['json' => $data, '_no_layout' => true]];
|
||||
}
|
||||
}
|
1
view/template/internal/json.php
Normal file
1
view/template/internal/json.php
Normal file
|
@ -0,0 +1 @@
|
|||
<?php echo json_encode($json ?? [], JSON_PRETTY_PRINT) ?>
|
Loading…
Add table
Reference in a new issue