コード例 #1
0
        /// <summary>
        /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
        /// </summary>
        /// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
        /// <param name="cache">The <see cref="CacheBase"/> used for this strategy.</param>
        /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
        public static ICacheConcurrencyStrategy CreateCache(string usage, CacheBase cache)
        {
            if (log.IsDebugEnabled())
            {
                log.Debug("cache for: {0} usage strategy: {1}", cache.RegionName, usage);
            }

            ICacheConcurrencyStrategy ccs;

            switch (usage)
            {
            case ReadOnly:
                ccs = new ReadOnlyCache();
                break;

            case ReadWrite:
                ccs = new ReadWriteCache();
                break;

            case NonstrictReadWrite:
                ccs = new NonstrictReadWriteCache();
                break;

            //case CacheFactory.Transactional:
            //	ccs = new TransactionalCache();
            //	break;
            default:
                throw new MappingException(
                          "cache usage attribute should be read-write, read-only or nonstrict-read-write");
            }

            ccs.Cache = cache;

            return(ccs);
        }
コード例 #2
0
		/// <summary>
		/// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
		/// </summary>
		/// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
		/// <param name="name">The name of the class the strategy is being created for.</param>
		/// <param name="mutable"><c>true</c> if the object being stored in the cache is mutable.</param>
		/// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
		// was private in h2.1
		public static ICacheConcurrencyStrategy CreateCache( string usage, string name, bool mutable )
		{
			if( log.IsDebugEnabled )
			{
				log.Debug( string.Format( "cache for: {0} usage strategy: {1}", name, usage ) );
			}

			ICacheConcurrencyStrategy ccs = null;
			switch( usage )
			{
				case CacheFactory.ReadOnly:
					if( mutable )
					{
						log.Warn( "read-only cache configured for mutable: " + name );
					}
					ccs = new ReadOnlyCache();
					break;
				case CacheFactory.ReadWrite:
					ccs = new ReadWriteCache();
					break;
				case CacheFactory.NonstrictReadWrite:
					ccs = new NonstrictReadWriteCache();
					break;
				//case CacheFactory.Transactional:
				//	ccs = new TransactionalCache();
				//	break;
				default:
					throw new MappingException( "cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional" );
			}

			return ccs;
		}
コード例 #3
0
        /// <summary>
        /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
        /// </summary>
        /// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
        /// <param name="name">The name of the class the strategy is being created for.</param>
        /// <param name="mutable"><see langword="true" /> if the object being stored in the cache is mutable.</param>
        /// <param name="settings">Used to retrieve the global cache region prefix.</param>
        /// <param name="properties">Properties the cache provider can use to configure the cache.</param>
        /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
        public static ICacheConcurrencyStrategy CreateCache(string usage, string name, bool mutable, Settings settings,
                                                            IDictionary <string, string> properties)
        {
            if (usage == null || !settings.IsSecondLevelCacheEnabled)
            {
                return(null);                                                                  //no cache
            }
            string prefix = settings.CacheRegionPrefix;

            if (prefix != null)
            {
                name = prefix + '.' + name;
            }

            if (log.IsDebugEnabled())
            {
                log.Debug("cache for: {0} usage strategy: {1}", name, usage);
            }

            ICacheConcurrencyStrategy ccs;

            switch (usage)
            {
            case ReadOnly:
                if (mutable)
                {
                    log.Warn("read-only cache configured for mutable: {0}", name);
                }
                ccs = new ReadOnlyCache();
                break;

            case ReadWrite:
                ccs = new ReadWriteCache();
                break;

            case NonstrictReadWrite:
                ccs = new NonstrictReadWriteCache();
                break;

            //case CacheFactory.Transactional:
            //	ccs = new TransactionalCache();
            //	break;
            default:
                throw new MappingException(
                          "cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional");
            }

            try
            {
                ccs.Cache = settings.CacheProvider.BuildCache(name, properties);
            }
            catch (CacheException e)
            {
                throw new HibernateException("Could not instantiate cache implementation", e);
            }

            return(ccs);
        }
コード例 #4
0
		/// <summary>
		/// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
		/// </summary>
		/// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
		/// <param name="name">The name of the class the strategy is being created for.</param>
		/// <param name="mutable"><see langword="true" /> if the object being stored in the cache is mutable.</param>
		/// <param name="settings">Used to retrieve the global cache region prefix.</param>
		/// <param name="properties">Properties the cache provider can use to configure the cache.</param>
		/// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
		public static ICacheConcurrencyStrategy CreateCache(string usage, string name, bool mutable, Settings settings,
		                                                    IDictionary<string,string> properties)
		{
			if (usage == null || !settings.IsSecondLevelCacheEnabled) return null; //no cache

			string prefix = settings.CacheRegionPrefix;
			if (prefix != null) name = prefix + '.' + name;

			if (log.IsDebugEnabled)
			{
				log.Debug(string.Format("cache for: {0} usage strategy: {1}", name, usage));
			}

			ICacheConcurrencyStrategy ccs;
			switch (usage)
			{
				case ReadOnly:
					if (mutable)
					{
						log.Warn("read-only cache configured for mutable: " + name);
					}
					ccs = new ReadOnlyCache();
					break;
				case ReadWrite:
					ccs = new ReadWriteCache();
					break;
				case NonstrictReadWrite:
					ccs = new NonstrictReadWriteCache();
					break;
					//case CacheFactory.Transactional:
					//	ccs = new TransactionalCache();
					//	break;
				default:
					throw new MappingException(
						"cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional");
			}

			ICache impl;
			try
			{
				impl = settings.CacheProvider.BuildCache(name, properties);
			}
			catch (CacheException e)
			{
				throw new HibernateException("Could not instantiate cache implementation", e);
			}
			ccs.Cache = impl;

			return ccs;
		}
コード例 #5
0
        /// <summary>
        /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
        /// </summary>
        /// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
        /// <param name="name">The name of the class the strategy is being created for.</param>
        /// <param name="mutable"><c>true</c> if the object being stored in the cache is mutable.</param>
        /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
        // was private in h2.1
        public static ICacheConcurrencyStrategy CreateCache(string usage, string name, bool mutable)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("cache for: {0} usage strategy: {1}", name, usage));
            }

            ICacheConcurrencyStrategy ccs = null;

            switch (usage)
            {
            case CacheFactory.ReadOnly:
                if (mutable)
                {
                    log.Warn("read-only cache configured for mutable: " + name);
                }
                ccs = new ReadOnlyCache();
                break;

            case CacheFactory.ReadWrite:
                ccs = new ReadWriteCache();
                break;

            case CacheFactory.NonstrictReadWrite:
                ccs = new NonstrictReadWriteCache();
                break;

            //case CacheFactory.Transactional:
            //	ccs = new TransactionalCache();
            //	break;
            default:
                throw new MappingException("cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional");
            }

            return(ccs);
        }