Exemplo n.º 1
0
        /// <summary>
        /// Instantiates a cache manager from app.config or web.config.
        /// Use this overload only if you cannot use the generic overload. The return type will be <c>Object</c>.
        /// This method can be used for example in conjunction with dependency injection frameworks.
        /// <para>
        /// The <paramref name="cacheName"/> must match with one cache element defined in your
        /// config file.
        /// </para>
        /// </summary>
        /// <param name="cacheValueType">The type of the cache item value.</param>
        /// <param name="cacheName">The name of the cache.</param>
        /// <param name="sectionName">
        /// The cache manager section name.
        /// </param>
        /// <returns>The cache manager instance.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if the <paramref name="cacheValueType"/>, <paramref name="cacheName"/> or <paramref name="sectionName"/>
        /// is null or an empty.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// Thrown if there are configuration errors within the cacheManager section.
        /// Thrown if no cacheManager section is defined or on certain configuration errors related
        /// to the cache handles.
        /// </exception>
        public static object FromConfiguration(Type cacheValueType, string cacheName, string sectionName)
        {
            var cfg = ConfigurationBuilder.LoadConfiguration(sectionName, cacheName);

            return(CacheFactory.FromConfiguration(cacheValueType, cacheName, cfg));
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>Instantiates a cache manager from app.config or web.config.</para>
        /// <para>
        /// The <paramref name="cacheName"/> must match with one cache element defined in your
        /// config file.
        /// </para>
        /// </summary>
        /// <example>
        /// The following example show how to use the CacheFactory to create a new cache manager
        /// instance from app/web.config.
        /// <code>
        /// <![CDATA[
        ///     var cache = CacheFactory.FromConfiguration<object>("cache", "section");
        ///     cache.Add("key", "value");
        /// ]]>
        /// </code>
        /// </example>
        /// <param name="cacheName">The name of the cache.</param>
        /// <param name="sectionName">
        /// The cache manager section name.
        /// </param>
        /// <typeparam name="TCacheValue">The type of the cache item value.</typeparam>
        /// <returns>The cache manager instance.</returns>
        /// <seealso cref="ICacheManager{TCacheValue}"/>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if the <paramref name="cacheName"/> or <paramref name="sectionName"/> is null or an empty.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// Thrown if there are configuration errors within the cacheManager section.
        /// Thrown if no cacheManager section is defined or on certain configuration errors related
        /// to the cache handles.
        /// </exception>
        public static ICacheManager <TCacheValue> FromConfiguration <TCacheValue>(string cacheName, string sectionName)
        {
            var cfg = ConfigurationBuilder.LoadConfiguration(sectionName, cacheName);

            return(CacheFactory.FromConfiguration <TCacheValue>(cacheName, cfg));
        }