コード例 #1
0
        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));
            }
        }
コード例 #2
0
        public ICache GetCacher(string name)
        {
            ICache cache = CacheUtil.GetDefaultCache();

            if (cache is AbstractCache)
            {
                ((AbstractCache)cache).CacheName = name;
            }
            return(cache);
        }
コード例 #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);
        }
コード例 #4
0
 protected IEnumerable <SettingNode> TryGetNodes(IEnumerable <SettingNode> settingNodes, string path)
 {
     return(CacheUtil.TryGetNodes(settingNodes, path));
 }
コード例 #5
0
 protected string TryGetValue(IEnumerable <SettingNode> settingNodes, string path)
 {
     return(CacheUtil.TryGetValue(settingNodes, path));
 }