// Varies the output cache based on the contact's gender
        public static IOutputCacheKeyOptions VaryByContactGender(this IOutputCacheKeyOptions options)
        {
            // Adds the ContactGenderOutputCacheKey to the options object
            options.AddCacheKey(new ContactGenderOutputCacheKey());

            return(options);
        }
Exemplo n.º 2
0
    /// <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));
    }
Exemplo n.º 3
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));
        }
 public static IOutputCacheKeyOptions VarByAssetsCookie(this IOutputCacheKeyOptions options)
 {
     options.AddCacheKey(new AssetsOutputCacheKey());
     return(options);
 }