Internal: Add APCu cache cleaning triggers. Complements commit b5d44b38. - refs GH#4405 (#dangerous)

pull/4544/head
Yannick Warnier 3 years ago
parent ed4382a7a4
commit 5c6281ebf3
  1. 1
      main/admin/configure_extensions.php
  2. 3
      main/admin/configure_plugin.php
  3. 37
      main/admin/settings.php
  4. 31
      main/inc/lib/api.lib.php

@ -68,6 +68,7 @@ if (isset($_POST['activeExtension'])) {
Database::query($sql);
break;
}
api_flush_settings_cache(api_get_current_access_url_id());
}
$listActiveServices = [];

@ -77,7 +77,7 @@ if (isset($form)) {
'',
'',
'',
api_get_current_access_url_id(),
$accessUrlId,
1
);
}
@ -88,6 +88,7 @@ if (isset($form)) {
$pluginName,
api_get_utc_datetime()
);
api_flush_settings_cache($accessUrlId);
if (!empty($pluginInfo['plugin_class'])) {
/** @var \Plugin $objPlugin */

@ -96,7 +96,11 @@ $url_id = api_get_current_access_url_id();
$settings = null;
$flushSettings = false;
$cacheAvailable = api_get_configuration_value('apc');
$multipleUrlsEnabled = false;
if (api_is_multiple_url_enabled()) {
$multipleUrlsEnabled = true;
}
// Build the form.
if (!empty($_GET['category']) &&
@ -107,7 +111,6 @@ if (!empty($_GET['category']) &&
$settings = $settings_array['settings'];
$settings_by_access_list = $settings_array['settings_by_access_list'];
$form = generateSettingsForm($settings, $settings_by_access_list);
$multipleUrlsEnabled = false;
if ($form->validate()) {
$values = $form->exportValues();
@ -115,8 +118,7 @@ if (!empty($_GET['category']) &&
$mark_all = false;
$un_mark_all = false;
if (api_is_multiple_url_enabled()) {
$multipleUrlsEnabled = true;
if ($multipleUrlsEnabled) {
if (isset($values['buttons_in_action_right']) &&
isset($values['buttons_in_action_right']['mark_all'])
) {
@ -306,24 +308,8 @@ if (!empty($_GET['category']) &&
api_get_utc_datetime(),
$user_id
);
if ($cacheAvailable && $flushSettings) {
// Delete the APCu-stored settings array, if present
$apcRootVarName = api_get_configuration_value('apc_prefix').'settings_';
$apcVarName = $apcRootVarName.$url_id;
apcu_delete($apcVarName);
if ($multipleUrlsEnabled && $url_id === 1) {
// if we are on the main URL of a multi-url portal, we must
// invalidate the cache for all other URLs as well as some
// main settings span multiple URLs
$urls = api_get_access_urls();
foreach ($urls as $i => $row) {
if ($row['id'] == 1) {
continue;
}
$apcVarName = $apcRootVarName.$row['id'];
apcu_delete($apcVarName);
}
}
if ($flushSettings) {
api_flush_settings_cache($url_id);
}
// Add event configuration settings variable to the system log.
if (is_array($keys) && count($keys) > 0) {
@ -458,6 +444,7 @@ if (!empty($_GET['category'])) {
switch ($_GET['category']) {
case 'Regions':
handleRegions();
$flushSettings = true;
break;
case 'Plugins':
// Displaying the extensions: Plugins.
@ -510,16 +497,19 @@ if (!empty($_GET['category'])) {
echo '</div>';
echo '</div>';
$flushSettings = true;
break;
case 'Stylesheets':
// Displaying the extensions: Stylesheets.
handleStylesheets();
$flushSettings = true;
break;
case 'Search':
handleSearch();
break;
case 'Templates':
handleTemplates();
$flushSettings = true;
break;
case 'search_setting':
if (isset($_REQUEST['search_field'])) {
@ -534,6 +524,9 @@ if (!empty($_GET['category'])) {
}
}
$content = ob_get_clean();
if ($flushSettings) {
api_flush_settings_cache($url_id);
}
// Including the header (banner).
Display::display_header($tool_name);

@ -10390,3 +10390,34 @@ function api_calculate_increment_percent(int $newValue, int $oldValue)
return $result;
}
/**
* Erase settings from cache (because of some update) if applicable
* @param int $url_id The ID of the present URL
*/
function api_flush_settings_cache(int $url_id): bool
{
$cacheAvailable = api_get_configuration_value('apc');
if (!$cacheAvailable) {
return false;
}
$apcRootVarName = api_get_configuration_value('apc_prefix').'settings_';
// Delete the APCu-stored settings array, if present
$apcVarName = $apcRootVarName.$url_id;
apcu_delete($apcVarName);
if (api_is_multiple_url_enabled() && $url_id === 1) {
// if we are on the main URL of a multi-url portal, we must
// invalidate the cache for all other URLs as well as some
// main settings span multiple URLs
$urls = api_get_access_urls();
foreach ($urls as $i => $row) {
if ($row['id'] == 1) {
continue;
}
$apcVarName = $apcRootVarName.$row['id'];
apcu_delete($apcVarName);
}
}
return true;
}

Loading…
Cancel
Save