Update apc cache if exists fixes #1959 BT#12768

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent bd8537963e
commit 66237ed991
  1. 4
      main/auth/profile.php
  2. 15
      main/inc/lib/api.lib.php

@ -103,7 +103,7 @@ $user_data = api_get_user_info(
false,
false,
false,
false
true
);
$array_list_key = UserManager::get_api_keys(api_get_user_id());
$id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
@ -706,7 +706,7 @@ if ($form->validate()) {
false,
false,
false,
false
true
);
Session::write('_user', $userInfo);

@ -1443,7 +1443,7 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
* @param bool $loadExtraData
* @param bool $loadOnlyVisibleExtraData Get the user extra fields that are visible
* @param bool $loadAvatars turn off to improve performance and if avatars are not needed.
* @param bool $enableCache if true check the apc cache
* @param bool $updateCache update apc cache if exists
*
* @return array $user_info user_id, lastname, firstname, username, email, etc
* @author Patrick Cool <patrick.cool@UGent.be>
@ -1457,11 +1457,11 @@ function api_get_user_info(
$loadExtraData = false,
$loadOnlyVisibleExtraData = false,
$loadAvatars = true,
$enableCache = true
$updateCache = false
) {
$apcVar = null;
$user = false;
$cacheAvailable = api_get_configuration_value('apc') && $enableCache;
$cacheAvailable = api_get_configuration_value('apc');
if (empty($user_id)) {
$userFromSession = Session::read('_user');
@ -1470,11 +1470,15 @@ function api_get_user_info(
if ($cacheAvailable === true) {
$apcVar = api_get_configuration_value('apc_prefix').'userinfo_'.$userFromSession['user_id'];
if (apcu_exists($apcVar)) {
if ($updateCache) {
apcu_store($apcVar, $userFromSession, 60);
}
$user = apcu_fetch($apcVar);
} else {
$user = _api_format_user($userFromSession, $showPassword, $loadAvatars);
apcu_store($apcVar, $user, 60);
}
} else {
$user = _api_format_user($userFromSession, $showPassword, $loadAvatars);
}
@ -1491,7 +1495,7 @@ function api_get_user_info(
// Re-use user information if not stale and already stored in APCu
if ($cacheAvailable === true) {
$apcVar = api_get_configuration_value('apc_prefix').'userinfo_'.$user_id;
if (apcu_exists($apcVar)) {
if (apcu_exists($apcVar) && $updateCache == false) {
$user = apcu_fetch($apcVar);
return $user;
@ -1531,7 +1535,8 @@ function api_get_user_info(
}
$user = _api_format_user($result_array, $showPassword, $loadAvatars);
}
if (!empty($cacheAvailable)) {
if ($cacheAvailable === true) {
apcu_store($apcVar, $user, 60);
}

Loading…
Cancel
Save