Esempio n. 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private DNTCache()
        {
            if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached)
            {
                applyMemCached = true;
            }
            if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis)
            {
                applyRedis = true;
            }

            if (applyMemCached || applyRedis)
            {
                try
                {
                    cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType("Discuz.EntLib." + (applyMemCached ? "MemCachedStrategy" : "RedisStrategy") + ", Discuz.EntLib", false, true));
                }
                catch
                {
                    throw new Exception("请检查Discuz.EntLib.dll文件是否被放置在bin目录下并配置正确");
                }
            }
            else
            {
                cs = new DefaultCacheStrategy();

                objectXmlMap = rootXml.CreateElement("Cache");
                //建立内部XML文档.
                rootXml.AppendChild(objectXmlMap);
            }
        }
Esempio n. 2
0
 public static void Dispose()
 {
     if (MemCachedConfigs.GetConfig().ApplyMemCached&& pool != null)
     {
         pool.Shutdown();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private ShopCache()
        {
            if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached)
            {
                applyMemCached = true;
            }

            if (applyMemCached)
            {
                cs = new MemCachedStrategy();
            }
            else
            {
                cs           = new DefaultCacheStrategy();
                objectXmlMap = rootXml.CreateElement("Cache");
                //建立内部XML文档.
                rootXml.AppendChild(objectXmlMap);

                //LogVisitor clv = new CacheLogVisitor();
                //cs.Accept(clv);

                cacheConfigTimer.AutoReset = true;
                cacheConfigTimer.Enabled   = true;
                cacheConfigTimer.Elapsed  += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
                cacheConfigTimer.Start();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private DNTCache()
        {
            if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached)
            {
                applyMemCached = true;
            }
            if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis)
            {
                applyRedis = true;
            }
            if (LLServerConfigs.GetConfig() != null && LLServerConfigs.GetConfig().ApplyLLServer)
            {
                applyLLServer = true;
            }

            if (applyMemCached || applyRedis || applyLLServer)
            {
                try
                {
                    string cacheStratetyName;
                    if (applyMemCached)
                    {
                        cacheStratetyName = "MemCachedStrategy";
                    }
                    else if (applyRedis)
                    {
                        cacheStratetyName = "RedisStrategy";
                    }
                    else
                    {
                        cacheStratetyName = "LLStrategy";
                    }

                    cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType("Discuz.EntLib." + cacheStratetyName + ", Discuz.EntLib", false, true));
                }
                catch
                {
                    throw new Exception("请检查Discuz.EntLib.dll文件是否被放置在bin目录下并配置正确");
                }
            }
            else
            {
                cs = new DefaultCacheStrategy();
                if (rootXml.HasChildNodes)
                {
                    rootXml.RemoveAll();
                }

                objectXmlMap = rootXml.CreateElement("Cache");
                //建立内部XML文档.
                rootXml.AppendChild(objectXmlMap);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取主题所包含的Tag
        /// </summary>
        /// <param name="topicid">主题Id</param>
        /// <returns>List</returns>
        public static List <TagInfo> GetTagsListByTopic(int topicid)
        {
            List <TagInfo> tabInfoList = null;

            //只有在开启memcached时才会缓存tag标签
            if ((MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) ||
                (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis))
            {
                DNTCache cache = DNTCache.GetCacheService();
                tabInfoList = cache.RetrieveObject("/Forum/ShowTopic/Tag/" + topicid + "/") as List <TagInfo>;
                if (tabInfoList == null)
                {
                    tabInfoList = Discuz.Data.ForumTags.GetTagsListByTopic(topicid);
                    cache.AddObject("/Forum/ShowTopic/Tag/" + topicid + "/", tabInfoList);
                }
            }
            else
            {
                tabInfoList = Discuz.Data.ForumTags.GetTagsListByTopic(topicid);
            }

            return(tabInfoList);
        }