public override string GetVaryByCustomString(HttpContext context, string arg)
        {
            var options = OutputCacheKeyHelper.CreateOptions().VarByAssetsCookie();

            switch (arg)
            {
            case OutputCacheConsts.VarByCustom.Default:
                //options.VaryByHost().VaryByBrowser().VaryByUser();
                break;

            case OutputCacheConsts.VarByCustom.OnlineMarketing:
                options
                .VaryByCookieLevel()
                .VaryByPersona()
                .VaryByABTestVariant();
                break;
            }

            string cacheKey = OutputCacheKeyHelper.GetVaryByCustomString(context, arg, options);

            if (!String.IsNullOrEmpty(cacheKey))
            {
                return(cacheKey);
            }

            // Calls the base implementation if the provided custom string does not match any predefined configurations
            return(base.GetVaryByCustomString(context, arg));
        }
        public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            var options = OutputCacheKeyHelper.CreateOptions();

            switch (custom)
            {
            case "DefaultSet":
            default:
                options
                .VaryByBrowser()
                .VaryByHost();
                break;
            }

            var cacheKey = OutputCacheKeyHelper.GetVaryByCustomString(context, custom, options);

            return(!string.IsNullOrEmpty(cacheKey) ? cacheKey : base.GetVaryByCustomString(context, custom));
        }
Example #3
0
        /// <summary>
        /// Overrides basic application-wide implementation of the <see cref="P:System.Web.UI.PartialCachingAttribute.VaryByCustom" /> property.
        /// </summary>
        public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            var options         = OutputCacheKeyHelper.CreateOptions();
            var contactGroupKey = String.Empty;

            switch (custom)
            {
            case "DefaultProfile":
                options
                .VaryByUser()
                .VaryByHost()
                .VaryByCookieLevel();
                break;

            case "PageBuilderProfile":
                options
                .VaryByUser()
                .VaryByHost()
                .VaryByPersona()
                .VaryByABTestVariant()
                .VaryByCookieLevel();

                contactGroupKey = GetContactGroupCacheKey();
                break;
            }

            // Get cache key generated based on cache options
            var builtCacheKey = OutputCacheKeyHelper.GetVaryByCustomString(context, custom, options);

            // Combine cache options with custom contact group cache key if exists
            if (!String.IsNullOrEmpty(contactGroupKey))
            {
                builtCacheKey = String.Join("|", builtCacheKey, contactGroupKey);
            }

            if (!String.IsNullOrEmpty(builtCacheKey))
            {
                return(builtCacheKey);
            }

            return(base.GetVaryByCustomString(context, custom));
        }
    /// <summary>
    /// When a OutputCache VaryByCustom string is passed, can define various options to this to alter the Cache Name.
    /// </summary>
    /// <param name="context"></param>
    /// <param name="custom"></param>
    /// <returns></returns>
    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        // Creates the options object used to store individual cache key parts
        IOutputCacheKeyOptions options = OutputCacheKeyHelper.CreateOptions();

        // Selects a caching configuration according to the current custom string, allows semi-colon separate list
        foreach (string customItem in custom.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
        {
            switch (customItem.ToLowerInvariant())
            {
            case "default":
                // Sets the variables that compose the cache key for the 'Default' VaryByCustom string
                options
                .VaryByHost()
                .VaryByBrowser()
                .VaryByUser();
                break;

            case "onlinemarketing":
                // Sets the variables that compose the cache key for the 'OnlineMarketing' VaryByCustom string
                options
                .VaryByCookieLevel()
                .VaryByPersona()
                .VaryByABTestVariant();
                break;
            }
        }

        // Combines individual 'VaryBy' key parts into a cache key under which the output is cached
        string cacheKey = OutputCacheKeyHelper.GetVaryByCustomString(context, custom, options);

        // Returns the constructed cache key
        if (!String.IsNullOrEmpty(cacheKey))
        {
            return(cacheKey);
        }

        // Calls the base implementation if the provided custom string does not match any predefined configurations
        return(base.GetVaryByCustomString(context, custom));
    }
Example #5
0
        //EndDocSection:ApplicationError


        //DocSection:GetVaryByCustom
        public override string GetVaryByCustomString(HttpContext context, string arg)
        {
            // Creates the options object used to store individual cache key parts
            IOutputCacheKeyOptions options = OutputCacheKeyHelper.CreateOptions();

            // Selects a caching configuration according to the current custom string
            switch (arg)
            {
            case "Default":
                // Sets the variables that compose the cache key for the 'Default' VaryByCustom string
                options
                .VaryByHost()
                .VaryByBrowser()
                .VaryByUser();
                break;

            case "OnlineMarketing":
                // Sets the variables that compose the cache key for the 'OnlineMarketing' VaryByCustom string
                options
                .VaryByCookieLevel()
                .VaryByPersona()
                .VaryByABTestVariant();
                break;
            }

            // Combines individual 'VaryBy' key parts into a cache key under which the output is cached
            string cacheKey = OutputCacheKeyHelper.GetVaryByCustomString(context, arg, options);

            // Returns the constructed cache key
            if (!String.IsNullOrEmpty(cacheKey))
            {
                return(cacheKey);
            }

            // Calls the base implementation if the provided custom string does not match any predefined configurations
            return(base.GetVaryByCustomString(context, arg));
        }