JD2022-TU1/main/extern/UbiServices/custom/client-sdk/private/ubiservices/services/cacheInvalidationPolicy.cpp

237 lines
9.9 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "ubiservices/services/cacheInvalidationPolicy.h"
#if defined(US_SDK_SERVER)
#error This file shall not be part of the solution
#endif
#include "ubiservices/core/configs/configpriv.h"
#include "ubiservices/facadeInternal.h"
#if defined(US_MODULE_BATTLEPASS)
#include "ubiservices/services/battlepass/battlepassProxy.h"
#endif
#if defined(US_MODULE_CLUB)
#include "ubiservices/services/club/sessionManagerClubProxy.h"
#endif
#if defined(US_MODULE_FRIEND)
#include "ubiservices/services/friend/friendClientProxy.h"
#endif
#if defined(US_MODULE_NEWS)
#include "ubiservices/services/news/newsProxy.h"
#endif
#include "ubiservices/services/parameters/parametersClientProxy.h"
#if defined(US_MODULE_PROFILE)
#include "ubiservices/services/profile/profileClient.h"
#endif
#include "ubiservices/services/populations/populationsProxy.h"
#if defined(US_PRIMARY_STORE_ENABLED)
#include "ubiservices/services/secondaryStore/sessionManagerStore.h"
#include "ubiservices/services/secondaryStore/sessionManagerStoreProxy.h"
#endif // defined(US_PRIMARY_STORE_ENABLED)
#if defined(US_MODULE_USER)
#include "ubiservices/services/user/userLegalOptinsStatusProxy.h"
#include "ubiservices/services/user/userLocalizationProxy.h"
#include "ubiservices/services/user/userStatusProxy.h"
#endif
#if defined(US_MODULE_SSI)
#include "ubiservices/services/secondaryStoreInstantiation/storeAttributesAllProxy.h"
#include "ubiservices/services/secondaryStoreInstantiation/storeListsOfAttributesAllProxy.h"
#include "ubiservices/services/secondaryStoreInstantiation/storeRulesAllProxy.h"
#endif // US_MODULE_SSI
#include "ubiservices/sessionManager.h"
namespace US_NS {;
void CacheInvalidationPolicy::invalidateCaches(FacadeInternal& facade) const
{
#if defined(US_MODULE_BATTLEPASS)
invalidateCacheBattlepass(facade);
#endif
#if defined(US_MODULE_CLUB)
invalidateCacheClub(facade);
#endif
#if defined(US_MODULE_FRIEND)
invalidateCacheFriends(facade);
#endif
#if defined(US_MODULE_NEWS)
invalidateCacheNews(facade);
#endif
#if defined(US_MODULE_PROFILE)
invalidateCacheApplicationUsed(facade);
#endif
#if defined(US_MODULE_USER)
invalidateCacheUser(facade);
#endif
invalidateCacheParameters(facade);
#if defined(US_PRIMARY_STORE_ENABLED)
invalidateCacheSessionManagerStore(facade);
#endif
#if defined(US_MODULE_SSI)
invalidateCacheStoreAttributesAll(facade);
invalidateCacheStoreRulesAll(facade);
invalidateCacheStoreListsOfAttributesAll(facade);
#endif // US_MODULE_SSI
US_UNUSED(facade);
}
#if defined(US_MODULE_BATTLEPASS)
void CacheInvalidationPolicy::invalidateCacheBattlepass(FacadeInternal& facade) const
{
BattlepassProxy::invalidateCache(facade.getBattlepassClient(), CacheUnit::Battlepass);
BattlepassProxy::invalidateCache(facade.getBattlepassClient(), CacheUnit::BattlepassSeason);
BattlepassProxy::invalidateCache(facade.getBattlepassClient(), CacheUnit::BattlepassSeasonInfo);
BattlepassProxy::invalidateCache(facade.getBattlepassClient(), CacheUnit::BattlepassSeasonAll);
}
#endif
#if defined(US_MODULE_CLUB)
void CacheInvalidationPolicy::invalidateCacheClub(FacadeInternal& facade) const
{
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubRewards);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubBadges);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengeStatusCommunityCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengeStatusProfileCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengePoolsBundledCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubActions);
}
#endif
#if defined(US_MODULE_FRIEND)
void CacheInvalidationPolicy::invalidateCacheFriends(FacadeInternal& facade) const
{
FriendClientProxy::invalidateCache(facade.getFriendClient());
}
#endif
#if defined(US_MODULE_PROFILE)
void CacheInvalidationPolicy::invalidateCacheApplicationUsed(FacadeInternal& facade) const
{
facade.getProfileClient().invalidateCacheApplicationUsed();
}
#endif
#if defined(US_MODULE_USER)
void CacheInvalidationPolicy::invalidateCacheUser(FacadeInternal& facade) const
{
UserLegalOptinsStatusProxy::invalidateCache(facade.getUserClient());
UserLocalizationProxy::invalidateCache(facade.getUserClient());
UserStatusProxy::invalidateCache(facade.getUserClient());
}
#endif
void CacheInvalidationPolicy::invalidateCacheParameters(FacadeInternal& facade) const
{
ParametersClientProxy::invalidateCache(facade.getParametersClient(), CacheUnit::ParametersApplication);
ParametersClientProxy::invalidateCache(facade.getParametersClient(), CacheUnit::ParametersSpace);
}
#if defined(US_PRIMARY_STORE_ENABLED)
void CacheInvalidationPolicy::invalidateCacheSessionManagerStore(FacadeInternal& facade) const
{
#if defined(US_PRIMARY_STORE_WITH_API) && !defined(US_TARGET_SWITCH)
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreCatalog);
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreInventory);
#else
US_UNUSED(facade);
#endif
}
#endif // defined(US_PRIMARY_STORE_ENABLED)
#if defined(US_MODULE_SSI)
void CacheInvalidationPolicy::invalidateCacheStoreAttributesAll(FacadeInternal& facade) const
{
StoreAttributesAllProxy::invalidateCache(facade.getSecondaryStoreInstantiationClient());
}
void CacheInvalidationPolicy::invalidateCacheStoreRulesAll(FacadeInternal& facade) const
{
StoreRulesAllProxy::invalidateCache(facade.getSecondaryStoreInstantiationClient());
}
void CacheInvalidationPolicy::invalidateCacheStoreListsOfAttributesAll(FacadeInternal& facade) const
{
StoreListsOfAttributesAllProxy::invalidateCache(facade.getSecondaryStoreInstantiationClient());
}
#endif // US_MODULE_SSI
#if defined(US_MODULE_NEWS)
void CacheInvalidationPolicy::invalidateCacheNews(FacadeInternal& facade) const
{
NewsProxy::invalidateCache(facade.getNewsClient(), CacheUnit::NewsProfile);
NewsProxy::invalidateCache(facade.getNewsClient(), CacheUnit::NewsSpace);
}
#endif
#if defined(US_PRIMARY_STORE_ENABLED)
void CacheInvalidationNoPrimaryStoreCatalog::invalidateCacheSessionManagerStore(FacadeInternal& facade) const
{
#if defined(US_PRIMARY_STORE_WITH_API) && !defined(US_TARGET_SWITCH)
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreInventory);
#else
US_UNUSED(facade);
#endif
}
#endif // defined(US_PRIMARY_STORE_ENABLED)
CacheInvalidationResumeFromBackground::CacheInvalidationResumeFromBackground(ClockSteady::TTimeNano backgroundDuration)
: m_backgroundDuration(backgroundDuration)
{
#if !defined(US_TARGET_XONE) && !defined(US_TARGET_MANJARO)
US_UNUSED(m_backgroundDuration)
#endif
}
#if defined(US_PRIMARY_STORE_ENABLED)
void CacheInvalidationResumeFromBackground::invalidateCacheSessionManagerStore(FacadeInternal& facade) const
{
#if defined(US_PRIMARY_STORE_WITH_API) && !defined(US_TARGET_SWITCH) && !defined(US_TARGET_XONE) && !defined(US_TARGET_MANJARO)
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreInventory);
#elif defined(US_PRIMARY_STORE_WITH_API) && (defined(US_TARGET_XONE) || defined(US_TARGET_MANJARO))
const uint64 backgroundDurationMsec = ClockSteady::getMilliFromNano(m_backgroundDuration);
const uint64 minBackgroundDurationMsec = facade.getManager().getParametersInfo().m_paramsSettings.m_minBackgroundDurationForInventoryInvalidationMsec;
// Avoid invalidating the cache if the background duration was not sufficient to buy new items.
// When the minimum background is set to 0 in config, consider the mechanism deactivated and force the cache
// invalidation, no matter how long the background duration is (which could be below 1 ms).
if (minBackgroundDurationMsec == 0 || backgroundDurationMsec > minBackgroundDurationMsec)
{
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreInventory);
}
else
{
US_LOG(LogLevel::Info, LogCategory::PrimaryStore, "Inventory cache is not invalidated because background duration (" <<
backgroundDurationMsec << " ms) is below the minimum duration (" << minBackgroundDurationMsec << " ms)");
}
#else
US_UNUSED(facade);
#endif
}
#endif // defined(US_PRIMARY_STORE_ENABLED)
#if defined(US_MODULE_CLUB)
void CacheInvalidationResumeFromBackground::invalidateCacheClub(FacadeInternal& facade) const
{
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubBadges);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengeStatusCommunityCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengeStatusProfileCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubChallengePoolsBundledCache);
SessionManagerClubProxy::invalidateCache(facade, CacheUnit::ClubActions);
// CacheUnit::ClubRewards is not invalidated when resuming from background
}
#endif
void CacheInvalidationPrimaryStoreInventoryOnly::invalidateCaches(FacadeInternal& facade) const
{
#if defined(US_PRIMARY_STORE_WITH_API) && !defined(US_TARGET_SWITCH)
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreInventory);
#else
US_UNUSED(facade);
#endif
}
void CacheInvalidationPrimaryStoreCatalogOnly::invalidateCaches(FacadeInternal& facade) const
{
#if defined(US_PRIMARY_STORE_WITH_API) && defined(US_TARGET_WINDOWS)
SessionManagerStoreProxy::invalidateCache(facade.getManager().getSessionManagerStoreRW(), CacheUnit::PrimaryStoreCatalog);
#else
US_UNUSED(facade);
#endif // defined(US_PRIMARY_STORE_ENABLED) && defined(US_TARGET_WINDOWS)
}
};