Пример #1
0
        /// <summary>
        /// 返回指定ID的对象
        /// </summary>
        /// <param name="objId"></param>
        /// <returns></returns>
        public override object RetrieveObject(string objId)
        {
            object obj = base.RetrieveObject(objId);

            if (obj == null)
            {
                using (IRedisClient Redis = RedisManager.GetClient())
                {
                    obj = new ObjectSerializer().Deserialize(Redis.Get <byte[]>(objId));

                    if (obj != null && !objId.StartsWith("/Forum/ShowTopic/"))   //对ShowTopic页面缓存数据不放到本地缓存
                    {
                        if (objId.StartsWith("/Forum/ShowTopicGuestCachePage/")) //对游客缓存页面ShowTopic数据缓存设置有效时间
                        {
                            base.TimeOut = GeneralConfigs.GetConfig().Guestcachepagetimeout * 60;
                        }
                        if (objId.StartsWith("/Forum/ShowForumGuestCachePage/"))//对游客缓存页面ShowTopic数据缓存设置有效时间
                        {
                            base.TimeOut = RedisConfigs.GetConfig().CacheShowForumCacheTime * 60;
                        }
                        else
                        {
                            base.TimeOut = LocalCacheTime;
                        }

                        base.AddObject(objId, obj, TimeOut);
                    }
                }
            }
            return(obj);
        }
Пример #2
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);
            }
        }
Пример #3
0
        private static ConnectionMultiplexer InitRedis()
        {
            var redisConfigs = new RedisConfigs(_configs.GetSection("redis"));
            ConnectionMultiplexer reddisDbMultiplexer = StackExchange.Redis.ConnectionMultiplexer.Connect(redisConfigs.ConfigurationOptions);

            return(reddisDbMultiplexer);
        }
Пример #4
0
 public static RedisConfigs GetRedisConfigs(this IServiceProvider serviceProvider)
 {
     if (_RedisConfigs == null)
     {
         _RedisConfigs = GetConfiguration(serviceProvider).GetSection("RedisConfigs").Get <RedisConfigs>();
     }
     return(_RedisConfigs);
 }
Пример #5
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);
            }
        }
Пример #6
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);
        }
Пример #7
0
        public Startup(IConfiguration config)
        {
            // For unit tests.
            if (config == null)
            {
                return;
            }

            _config          = config;
            _rTokenConfig    = new JwtConfig(config.GetSection("jwtRefreshToken"));
            _sTokenConfig    = new JwtConfig(config.GetSection("jwtShortToken"));
            _rTokenKeyConfig = new SymmetricKeyConfig(config.GetSection("jwtRefreshTokenSigningKey"));
            _sTokenKeyConfig = new SymmetricKeyConfig(config.GetSection("jwtShortTokenSigningKey"));
            _redisConfigs    = new RedisConfigs(config.GetSection("redis"));
            _rabbitmqConfigs = new RabbitMqConfigs(config.GetSection("rabbitMq"));
            _rabbitmqRevokedTokenExchangeConfigs = new RabbitMqExchangeConfigs(config.GetSection("rabbitMq").GetSection("revokedTokenExchange"));

            _mongoDbLogConfigs        = new MongoDbConfigs(config.GetSection("mongoLogDb"));
            _infoLogCollectionConfig  = new MongoCollectionConfig(config.GetSection("mongoLogDb").GetSection("infoLogCollection"));
            _errorLogCollectionConfig = new MongoCollectionConfig(config.GetSection("mongoLogDb").GetSection("errorLogCollection"));

            _mongoDbConfigs = new MongoDbConfigs(config.GetSection("mongoDb"));
            _accountRTokensCollectionConfig = new MongoCollectionConfig(config.GetSection("mongoDb").GetSection("accountRTokenCollection"));
        }