Exemplo n.º 1
0
        /// <summary>
        /// Creates a CacheItemPolicy instance from cache item policy configuration for the specified name.
        /// </summary>
        /// <param name="name">The configured cache item policy name.</param>
        /// <returns>
        /// An instance of <see cref="CacheItemPolicy" /> or null if the
        /// cache item policy configuration for the specified name was not found.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public CacheItemPolicy Create(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            var configurationItem = _index[name];

            return(CacheItemPolicyHelpers.CreateCacheItemPolicy(configurationItem));
        }
        /// <summary>
        /// Creates a CacheItemPolicy instance from cache item policy configuration for the specified name.
        /// </summary>
        /// <param name="name">The configured cache item policy name.</param>
        /// <returns>
        /// An instance of <see cref="CacheItemPolicy" /> or null if the
        /// cache item policy configuration for the specified name was not found.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public CacheItemPolicy Create(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            var configurationItem = _configuration
                                    .CacheItemPolicyConfigurationItems
                                    .FirstOrDefault(item =>
                                                    item.Enabled && item.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
                                                    );

            if (null == configurationItem || false == configurationItem.Enabled)
            {
                return(null);
            }

            return(CacheItemPolicyHelpers.CreateCacheItemPolicy(configurationItem));
        }