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); Database::query($sql);
break; break;
} }
api_flush_settings_cache(api_get_current_access_url_id());
} }
$listActiveServices = []; $listActiveServices = [];

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

@ -96,7 +96,11 @@ $url_id = api_get_current_access_url_id();
$settings = null; $settings = null;
$flushSettings = false; $flushSettings = false;
$cacheAvailable = api_get_configuration_value('apc'); $multipleUrlsEnabled = false;
if (api_is_multiple_url_enabled()) {
$multipleUrlsEnabled = true;
}
// Build the form. // Build the form.
if (!empty($_GET['category']) && if (!empty($_GET['category']) &&
@ -107,7 +111,6 @@ if (!empty($_GET['category']) &&
$settings = $settings_array['settings']; $settings = $settings_array['settings'];
$settings_by_access_list = $settings_array['settings_by_access_list']; $settings_by_access_list = $settings_array['settings_by_access_list'];
$form = generateSettingsForm($settings, $settings_by_access_list); $form = generateSettingsForm($settings, $settings_by_access_list);
$multipleUrlsEnabled = false;
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
@ -115,8 +118,7 @@ if (!empty($_GET['category']) &&
$mark_all = false; $mark_all = false;
$un_mark_all = false; $un_mark_all = false;
if (api_is_multiple_url_enabled()) { if ($multipleUrlsEnabled) {
$multipleUrlsEnabled = true;
if (isset($values['buttons_in_action_right']) && if (isset($values['buttons_in_action_right']) &&
isset($values['buttons_in_action_right']['mark_all']) isset($values['buttons_in_action_right']['mark_all'])
) { ) {
@ -306,24 +308,8 @@ if (!empty($_GET['category']) &&
api_get_utc_datetime(), api_get_utc_datetime(),
$user_id $user_id
); );
if ($cacheAvailable && $flushSettings) { if ($flushSettings) {
// Delete the APCu-stored settings array, if present api_flush_settings_cache($url_id);
$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);
}
}
} }
// Add event configuration settings variable to the system log. // Add event configuration settings variable to the system log.
if (is_array($keys) && count($keys) > 0) { if (is_array($keys) && count($keys) > 0) {
@ -458,6 +444,7 @@ if (!empty($_GET['category'])) {
switch ($_GET['category']) { switch ($_GET['category']) {
case 'Regions': case 'Regions':
handleRegions(); handleRegions();
$flushSettings = true;
break; break;
case 'Plugins': case 'Plugins':
// Displaying the extensions: Plugins. // Displaying the extensions: Plugins.
@ -510,16 +497,19 @@ if (!empty($_GET['category'])) {
echo '</div>'; echo '</div>';
echo '</div>'; echo '</div>';
$flushSettings = true;
break; break;
case 'Stylesheets': case 'Stylesheets':
// Displaying the extensions: Stylesheets. // Displaying the extensions: Stylesheets.
handleStylesheets(); handleStylesheets();
$flushSettings = true;
break; break;
case 'Search': case 'Search':
handleSearch(); handleSearch();
break; break;
case 'Templates': case 'Templates':
handleTemplates(); handleTemplates();
$flushSettings = true;
break; break;
case 'search_setting': case 'search_setting':
if (isset($_REQUEST['search_field'])) { if (isset($_REQUEST['search_field'])) {
@ -534,6 +524,9 @@ if (!empty($_GET['category'])) {
} }
} }
$content = ob_get_clean(); $content = ob_get_clean();
if ($flushSettings) {
api_flush_settings_cache($url_id);
}
// Including the header (banner). // Including the header (banner).
Display::display_header($tool_name); Display::display_header($tool_name);

@ -10390,3 +10390,34 @@ function api_calculate_increment_percent(int $newValue, int $oldValue)
return $result; 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