Experimental method to clear APC cache from PHP-CLI #2554 #1943

This commit is contained in:
Kijin Sung 2025-08-24 22:16:39 +09:00
parent e0033ac2fc
commit 771dbfe114
3 changed files with 98 additions and 6 deletions

View file

@ -1266,6 +1266,62 @@ class ModuleController extends Module
return executeQuery('module.deleteModuleFileBox', $args);
}
/**
* API call to clear cache entries.
*
* This can be used to clear the APC cache from CLI scripts,
* such as async tasks run from crontab.
*/
public function procModuleClearCache()
{
// This is a JSON API.
Context::setResponseMethod('JSON');
if (PHP_SAPI === 'cli')
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Get cache keys to clear.
$keys = Context::get('keys');
if (!$keys)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
if (!is_array($keys))
{
$keys = [$keys];
}
// Verify the API signature.
$keystring = implode('|', $keys);
$signature = Context::get('signature');
if (!$signature)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
if (!Rhymix\Framework\Security::verifySignature($keystring, $signature))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Clear the requested cache keys.
foreach ($keys as $key)
{
if ($key === '*')
{
Rhymix\Framework\Cache::clearAll();
}
elseif (preg_match('/^([^:]+):\*$/', $key, $matches))
{
Rhymix\Framework\Cache::clearGroup($matches[1]);
}
else
{
Rhymix\Framework\Cache::delete($key);
}
}
}
/**
* @brief function of locking (timeout is in seconds)
*/