/// <summary> /// 系统消息发送器构建 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <param name="sqlType">数据库类型</param> /// <param name="redisOptions">Redis缓存服务器信息</param> /// <param name="keepAlive">是否保持缓存服务器长连接</param> /// <param name="cacheItems">需要缓存的数据类型</param> /// <param name="level2CacheSeconds">二级缓存时间(单位:秒)</param> public static void Factory(string connectionString, SqlProviderType sqlType, string redisOptions, bool keepAlive = true, CacheItemType[] cacheItems = null, int level2CacheSeconds = 30) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new ArgumentNullException(nameof(connectionString)); } Configs.SqlConnectionString = connectionString; Configs.SqlType = sqlType; if (CacheCollection.Count < 1) { if (cacheItems == null || cacheItems.Length < 1) { cacheItems = new[] { CacheItemType.SystemGolbalConfig, CacheItemType.AreaForum, CacheItemType.UserLevelConfig }; } DataCacheExtensions.UseDataCache(redisOptions, keepAlive, cacheItems, level2CacheSeconds); } }
public Startup(IHostingEnvironment env) { Application.Start(new ApplicationContext(env)); // Set up configuration sources. var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json") .AddEnvironmentVariables(); WebRootPath = env.WebRootPath; Configuration = builder.Build(); _sqlType = new Func <SqlProviderType>(() => { string sqltype = Configuration["Data:SqlType"] ?? string.Empty; switch (sqltype.ToLower()) { case "npgsql": return(SqlProviderType.NpgSQL); case "mssql": default: return(SqlProviderType.SqlServer); } }).Invoke(); _sqlConn = Configuration["Data:DefaultConnection:ConnectionString"]; string redisConn = Configuration["Redis:ConnectString"];//Redis缓存服务器信息 //使用缓存 DataCacheExtensions.UseDataCache(new DataCacheServerOptions { KeepAlive = true, CacheItems = null, RedisConnectionString = redisConn, InitIfNull = false, SqlType = _sqlType, SqlConnection = _sqlConn, Level2CacheSeconds = int.Parse(Configuration["Redis:Level2CacheSeconds"]) }); #region 开启线程 执行索引库写队列处理 AreaIndexManager.Instance.StartNewThread(); MallProductIndexManager.Instance.StartNewThread(); MerchantProductIndexManager.Instance.StartNewThread(); MerchantIndexManager.Instance.StartNewThread(); JobIndexManager.Instance.StartNewThread(); #endregion }
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); if (env.IsEnvironment("Development")) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. builder.AddApplicationInsightsSettings(developerMode: true); } builder.AddEnvironmentVariables(); Configuration = builder.Build(); _sqlType = new Func <SqlProviderType>(() => { string sqltype = Configuration["Data:SqlType"] ?? string.Empty; switch (sqltype.ToLower()) { case "npgsql": return(SqlProviderType.NpgSQL); case "mssql": default: return(SqlProviderType.SqlServer); } }).Invoke(); _sqlConn = Configuration["Data:DefaultConnection:ConnectionString"]; string redisConn = Configuration["Redis:ConnectString"];//Redis缓存服务器信息 //缓存 DataCacheExtensions.UseDataCache(new DataCacheServerOptions { CacheItems = null, InitIfNull = true, KeepAlive = true, RedisConnectionString = redisConn, SqlConnection = _sqlConn, SqlType = _sqlType, Level2CacheSeconds = int.Parse(Configuration["Redis:Level2CacheSeconds"]) }); }
/// <summary> /// 注入数据缓存 /// </summary> public static void InjectionDataCache(bool isreset = false) { //注入数据缓存组件 DataCacheExtensions.UseDataCache(new DataCacheServerOptions { CacheItems = null, InitIfNull = true, RedisConnectionString = DataCacheRedisConnectionString, SqlConnection = KylinDBConnectionString, SqlType = SqlType, KeepAlive = true }); if (isreset) { CacheCollection.Reset(); } }