public override void InitSetting(IEnumerable <SettingNode> settingNodes)
        {
            base.InitSetting(settingNodes);

            firstCache  = CacheUtil.TryCreateCache(settingNodes, "firstType");
            secondCache = CacheUtil.TryCreateCache(settingNodes, "secondType");
            if (firstCache == null)
            {
                firstCache = new AspnetCache();
            }

            if (secondCache == null)
            {
                throw new MissConfigurationException(settingNodes, "secondType");
            }

            if (firstCache.GetType() == secondCache.GetType())
            {
                throw new ConfigurationException(String.Format("一二级缓存的类型不能一致,当前皆为 {0}。", firstCache.GetType().FullName));
            }

            if (firstCache != this)
            {
                CacheUtil.InitCache(firstCache, CacheUtil.GetCacheSettingNode(settingNodes, firstCache));
            }
            if (secondCache != this)
            {
                CacheUtil.InitCache(secondCache, CacheUtil.GetCacheSettingNode(settingNodes, secondCache));
            }
        }
        public virtual ICache GetCacher(string name)
        {
            ICache cache = cacheDic.TryGetValue(name);

            if (cache == null)
            {
                SettingNode node = cacheNodes.TryGetValue(name);

                if (node == null)
                {
                    cache = CacheUtil.GetDefaultCache();
                }
                else
                {
                    cache = CacheUtil.TryCreateCache(node, "type");
                    List <SettingNode> settingNodes = new List <SettingNode>()
                    {
                        node
                    };
                    settingNodes.Add(ToolSection.Instance.TryGetNode("cache/specifiableFactory"));
                    settingNodes.Add(ToolSection.Instance.TryGetNode("cache"));

                    CacheUtil.InitCache(cache, CacheUtil.GetCacheSettingNode(settingNodes, cache));
                }
                if (cache is AbstractCache)
                {
                    ((AbstractCache)cache).CacheName = name;
                }

                cacheDic[name] = cache;
            }
            return(cache);
        }
Exemple #3
0
        public static ICache GetDefaultCache(bool init = true)
        {
            SettingNode        cacheNode    = ToolSection.Instance.TryGetNode("cache");
            List <SettingNode> settingNodes = new List <SettingNode> {
                cacheNode
            };
            ICache cache = CacheUtil.TryCreateCache(cacheNode, "type");

            if (cache == null)
            {
                cache = new AspnetCache();
            }

            if (init)
            {
                CacheUtil.InitCache(cache, CacheUtil.GetCacheSettingNode(settingNodes, cache));
            }
            return(cache);
        }