<commit_before>﻿using System;
using System.Web;
using Sdl.Web.Common;
using Sdl.Web.Common.Configuration;
using Sdl.Web.Common.Logging;
using Sdl.Web.Mvc.Configuration;
using Tridion.ContentDelivery.AmbientData;
using Tridion.OutboundEmail.ContentDelivery.Profile;

namespace Sdl.Web.Modules.AudienceManager
{
    /// <summary>
    /// Factory class for Audience Manager User Profiles.
    /// </summary>
    public static class UserProfileFactory
    {
        private const string UserProfileCacheRegionName = "UserProfile";

        /// <summary>
        /// Gets the User Profile for the currently logged in user.
        /// </summary>
        public static UserProfile CurrentLoggedInUser
        {
            get
            {
                string currentUserName = HttpContext.Current.User.Identity.Name;
                using (new Tracer(currentUserName))
                {
                    if (string.IsNullOrEmpty(currentUserName))
                    {
                        return null;
                    }

                    return SiteConfiguration.CacheProvider.GetOrAdd(
                        currentUserName,
                        UserProfileCacheRegionName,
                        () => GetUserProfile(currentUserName)
                        );
                }
            }
        }

        /// <summary>
        /// Gets the User Profile for a given identification key.
        /// </summary>
        /// <param name="identificationKey">The identification key.</param>
        /// <returns>The <see cref="UserProfile"/> or <c>null</c> if no User Profile is found for the given identification key.</returns>
        public static UserProfile GetUserProfile(string identificationKey)
        {
            using (new Tracer(identificationKey))
            {
                if (string.IsNullOrEmpty(identificationKey))
                {
                    return null;
                }


                Localization localization = WebRequestContext.Localization;<commit_msg>TSI-2188 Prevent caching User Profile across Publications (TSI-2212)<commit_after>﻿using System;
using System.Web;
using Sdl.Web.Common.Configuration;
using Sdl.Web.Common.Logging;
using Sdl.Web.Mvc.Configuration;
using Tridion.ContentDelivery.AmbientData;
using Tridion.OutboundEmail.ContentDelivery.Profile;

namespace Sdl.Web.Modules.AudienceManager
{
    /// <summary>
    /// Factory class for Audience Manager User Profiles.
    /// </summary>
    public static class UserProfileFactory
    {
        private const string UserProfileCacheRegionName = "UserProfile";

        /// <summary>
        /// Gets the User Profile for the currently logged in user.
        /// </summary>
        public static UserProfile CurrentLoggedInUser
        {
            get
            {
                string currentUserName = HttpContext.Current.User.Identity.Name;
                using (new Tracer(currentUserName))
                {
                    if (string.IsNullOrEmpty(currentUserName))
                    {
                        return null;
                    }

                    // We include the Localization ID in the cache key, because a user name may resolve to a different Contact / User Profile
                    // in a different context Localization (associated with a different AM Sync Target).
                    string cacheKey = string.Format("{0}:{1}", currentUserName, WebRequestContext.Localization.LocalizationId);

                    return SiteConfiguration.CacheProvider.GetOrAdd(
                        cacheKey,
                        UserProfileCacheRegionName,
                        () => GetUserProfile(currentUserName)
                        );
                }
            }
        }

        /// <summary>
        /// Gets the User Profile for a given identification key.
        /// </summary>
        /// <param name="identificationKey">The identification key.</param>
        /// <returns>The <see cref="UserProfile"/> or <c>null</c> if no User Profile is found for the given identification key.</returns>
        public static UserProfile GetUserProfile(string identificationKey)
        {
            using (new Tracer(identificationKey))
            {
                if (string.IsNullOrEmpty(identificationKey))
                {
                    return null;
                }


                Localization localization = WebRequestContext.Localization;
{'fraction_non_alphanumeric': 0.0829202343397927, 'fraction_numerical': 0.002253267237494367, 'mean_word_length': 1.6968408262454435, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '408164', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1010, 'n_words': 270}