Summary description for CacheConfig.
Example #1
0
        private CacheConfig BuildCacheConfig(IKernel kernel, ComponentModel model)
        {
            string      cacheManagerId = GetCacheManagerId(model);
            CacheConfig cacheConfig    = new CacheConfig(kernel, cacheManagerId);

            return(cacheConfig);
        }
Example #2
0
        private CacheConfig CreateCacheConfig(IKernel kernel, ComponentModel model)
        {
            CacheConfig config = BuildCacheConfig(kernel, model);

            GatherCacheConfiguration(config, model);
            GatherCacheAttributes(config, model);
            return(config);
        }
Example #3
0
        private void GatherCacheAttributes(CacheConfig config, ComponentModel model)
        {
            MethodInfo[] methods = model.Implementation.GetMethods(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (MethodInfo method in methods)
            {
                if (method.IsDefined(typeof(CacheAttribute), true))
                {
                    CacheAttribute[] attributs      = method.GetCustomAttributes(typeof(CacheAttribute), true) as CacheAttribute[];
                    string           cacheManagerId = attributs[0].CacheManagerId;

                    config.AddMethod(method, cacheManagerId);
                }
            }
        }
Example #4
0
        public void ProcessModel(IKernel kernel, ComponentModel model)
        {
            CacheConfigHolder cacheConfigHolder = null;
            bool allowModelCache = IsCacheModelOn(kernel, model);

            if (allowModelCache)
            {
                model.Dependencies.Add(new DependencyModel(DependencyType.Service, null, typeof(CacheInterceptor), false));
                model.Interceptors.Add(new InterceptorReference(typeof(CacheInterceptor)));

                cacheConfigHolder = kernel[typeof(CacheConfigHolder)] as CacheConfigHolder;

                if (IsCacheModelOn(kernel, model))
                {
                    CacheConfig config = CreateCacheConfig(kernel, model);
                    cacheConfigHolder.Register(model.Implementation, config);
                }
            }
        }
Example #5
0
        private void GatherCacheConfiguration(CacheConfig config, ComponentModel model)
        {
            if (model.Configuration == null)
            {
                return;
            }

            // Get all children of cahce node
            IConfiguration cacheNode = model.Configuration.Children["cache"];

            if (cacheNode == null)
            {
                return;
            }

            foreach (IConfiguration configuration in model.Configuration.Children)
            {
                if (configuration.Name == "cache")
                {
                    foreach (IConfiguration methodNode in configuration.Children)
                    {
                        string methodName = string.Empty;

                        if (methodNode.Value == null)
                        {
                            methodName = methodNode.Attributes["name"];
                        }
                        else
                        {
                            methodName = methodNode.Value;
                        }

                        AssertNameIsNotEmptyIsNotNull(methodName, model);

                        config.AddMethodName(methodName, configuration.Attributes["ref"]);
                    }
                }
            }
        }
        /// <summary>
        /// Returns from the cache provider the value saved with the key generated
        /// using the specified <code>IMethodInvocation</code>. If the object is not
        /// found in the cache, the intercepted method is executed and its returned
        /// value is saved in the cached and returned by this method.
        /// </summary>
        /// <param name="invocation">the description of the intercepted method.</param>
        /// <param name="args">the arguments of the intercepted method.</param>
        /// <returns>the object stored in the cache.</returns>
        public object Intercept(IMethodInvocation invocation, params object[] args)
        {
            CacheConfig config = _cacheConfigHolder.GetConfig(invocation.Method.DeclaringType);

            if (config != null && config.IsMethodCache(invocation.Method))
            {
                ICacheManager cacheManager = config.GetCacheManager(invocation.Method);
                String        cacheKey     = cacheManager.CacheKeyGenerator.GenerateKey(invocation, args);
                object        result       = cacheManager[cacheKey];

                if (result == null)
                {
                    //call target/sub-interceptor
                    result = invocation.Proceed(args);

                    //cache method result
                    if (result == null)
                    {
                        cacheManager[cacheKey] = NULL_OBJECT;
                    }
                    else
                    {
                        cacheManager[cacheKey] = result;
                    }
                }
                else if (result == NULL_OBJECT)
                {
                    // convert the marker object back into a null value
                    result = null;
                }

                return(result);
            }
            else
            {
                return(invocation.Proceed(args));
            }
        }
		public void Register(Type implementation, CacheConfig config)
		{
			_impl2Config[implementation] = config;
		}
		private void GatherCacheAttributes(CacheConfig config, ComponentModel model)
		{
			MethodInfo[] methods = model.Implementation.GetMethods( 
				BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic );

			foreach(MethodInfo method in methods)
			{
				if (method.IsDefined( typeof(CacheAttribute), true ))
				{
					CacheAttribute[] attributs = method.GetCustomAttributes(typeof(CacheAttribute), true) as CacheAttribute[];
					string cacheManagerId = attributs[0].CacheManagerId;

					config.AddMethod( method, cacheManagerId );
				}
			}
		}
		private void GatherCacheConfiguration(CacheConfig config, ComponentModel model)
		{
			if (model.Configuration == null) return;
			
			// Get all children of cahce node
			IConfiguration cacheNode = model.Configuration.Children["cache"];

			if (cacheNode == null) return;

			foreach(IConfiguration configuration in model.Configuration.Children)
			{
				if (configuration.Name=="cache")
				{
					foreach(IConfiguration methodNode in configuration.Children)
					{
						string methodName = string.Empty;

						if (methodNode.Value==null)
						{
							methodName = methodNode.Attributes["name"];
						}
						else
						{
							methodName = methodNode.Value;
						}
						
						AssertNameIsNotEmptyIsNotNull(methodName, model);

						config.AddMethodName( methodName, configuration.Attributes["ref"] );
					}
				}
			}
		}
		private CacheConfig BuildCacheConfig(IKernel kernel,ComponentModel model)
		{
			string cacheManagerId = GetCacheManagerId(model);
			CacheConfig cacheConfig = new CacheConfig( kernel, cacheManagerId );
			return cacheConfig; 
		}
Example #11
0
 public void Register(Type implementation, CacheConfig config)
 {
     _impl2Config[implementation] = config;
 }