/// <summary> /// Call once to initialize the context. /// </summary> /// <typeparam name="TSite">The CMS site model type.</typeparam> /// <param name="cacheConfig">The cache config instance.</param> /// <param name="umbracoConfig">The umbraco config instance.</param> /// <param name="mapBuild">The map build instance.</param> /// <param name="cacheBuild">The cache build instance.</param> public static void Init <TSite>(ICacheConfig cacheConfig, IUmbracoConfig umbracoConfig, IMapBuild mapBuild, ICacheBuild cacheBuild) where TSite : class, ISite { MapRegistry = new MapRegistry(); Mapper = new Mapper(MapRegistry); CacheRegistry = new CacheRegistry(cacheConfig); QueryFactory = new UmbracoQueryFactory(); CmsFetcher = new UmbracoFetcher(umbracoConfig); Registry = new Registry(MapRegistry, Mapper, CacheRegistry, QueryFactory, CmsFetcher); SiteCaches = new SiteCaches(CacheRegistry); _siteFunc = () => { var cache = SiteCaches.Default; var host = HttpContext.Current?.Request.Url.Host ?? string.Empty; var sites = cache.Fetch <TSite>()?.ToList(); return(sites?.FirstOrDefault(site => site.Hosts?.Contains(host) ?? false) ?? sites?.FirstOrDefault()); }; _cacheFunc = () => { var site = _siteFunc(); return(SiteCaches.Get(site) as Cache); }; mapBuild.Setup(Registry); cacheBuild.Setup(CacheRegistry); }
public ConfigController(IOptions <ApiConfig> config, IUmbracoConfig umbraco, ICacheConfig cache, ICache cmsCache) { _config = config.Value; _umbracoConfig = umbraco; _cacheConfig = cache; _cache = cmsCache; }
public AccountCache(IMemoryCache cache, ICacheConfig config) { Ensure.Any.IsNotNull(cache, nameof(cache)); Ensure.Any.IsNotNull(config, nameof(config)); _cache = cache; _config = config; }
public SmartCache(IEnlapsedEvent enlapsedEvent, ObjectCache cache, string key, Func <T, R> function, ICacheConfig config) { this.config = config; this.cache = cache; this.key = key; this.function = function; this.topItems = new TopItems <ICacheItem>(enlapsedEvent, config.LockListMaxSize, config.MaxReports, config.MaxSummarySize); }
public RedisStore(IRedisFactory redisFactory, ICacheConfig cacheConfig, ICacheLogger cacheLogger) { this._cacheConfig = cacheConfig; this._cacheLogger = cacheLogger; long index = (typeof(T).FullName.Select(c => Convert.ToInt64(c)).Aggregate((cur, next) => cur + next)) % 16; this._cacheLogger.LogAsync($"Connecting to RedisDB:{index}", System.Diagnostics.Tracing.EventLevel.Verbose); this.DB = redisFactory.Connection?.GetDatabase((int)index); }
public static IServiceCollection AddCaches(this IServiceCollection services, Assembly assembly, ICacheConfig config) => services .AddMemoryCache() .AddScoped <ICacheProvider, CacheProvider>() .WithCaches(assembly) .AddStackExchangeRedisCache(x => { var options = x.ConfigurationOptions = ConfigurationOptions.Parse(config.ConnectionString); options.ReconnectRetryPolicy = new LinearRetry(config.LinearRetries); options.KeepAlive = config.KeepAliveSeconds; });
/// <summary> /// 读取配置列表 /// 从 JSON 文件 /// </summary> /// <param name="icc">ICacheConfig</param> /// <param name="listProperty">(可选)属性列表</param> /// <returns></returns> public static List <AqiConfig> CreateListFormJson(ICacheConfig icc, params string[] listProperty) { List <AqiConfig> listConfig = new List <AqiConfig>(); string propertyPath = String.Join(".", listProperty); try { //JSON路径 string jsonPath = icc.GetJsonFile(); if (!File.Exists(jsonPath)) { return(listConfig); } //读取JSON StreamReader sr = new StreamReader(jsonPath); string jsonText = sr.ReadToEnd(); //转JSON Object JObject jo = JObject.Parse(jsonText); JToken jt = jo.SelectToken(propertyPath); if (jt == null || !jt.HasValues) { return(null); } else if (jt is JObject) { //读取集合(任意个参数) JEnumerable <JToken> je = jt.Children(); foreach (JToken j in je) { if (j is JProperty) { JProperty jp = j as JProperty; //读取对象(仅一个配置) AqiConfig ac = createConfigFormJsonObject(jp.Value as JObject); ac.cName = jp.Name; if (ac != null) { listConfig.Add(ac); } } } } } catch (System.Exception ex) { throw new ConfigException("配置创建错误", ex); } return(listConfig); }
public CacheDatabase(Func <ICacheConfig> configFactory, Func <ICacheConfig, ConnectionMultiplexer> connectionMultiplexerFactory, Func <ICacheConfig, ConnectionMultiplexer, IDatabase> databaseFactory, ISerializer serializer = null) : this(serializer) { if (configFactory != null) { Config = configFactory(); } ConnectionMultiplexer = connectionMultiplexerFactory(Config); Database = databaseFactory(Config, ConnectionMultiplexer); }
/// <summary> /// 读取配置列表 /// 从 JSON 文件 /// </summary> /// <param name="icc">ICacheConfig</param> /// <param name="listProperty">(可选)属性列表</param> /// <returns></returns> public static List<AqiConfig> CreateListFormJson(ICacheConfig icc, params string[] listProperty) { List<AqiConfig> listConfig = new List<AqiConfig>(); string propertyPath = String.Join(".", listProperty); try { //JSON路径 string jsonPath = icc.GetJsonFile(); if(!File.Exists(jsonPath)) { return listConfig; } //读取JSON StreamReader sr = new StreamReader(jsonPath); string jsonText = sr.ReadToEnd(); //转JSON Object JObject jo = JObject.Parse(jsonText); JToken jt = jo.SelectToken(propertyPath); if (jt == null || !jt.HasValues) { return null; } else if (jt is JObject) { //读取集合(任意个参数) JEnumerable<JToken> je = jt.Children(); foreach (JToken j in je) { if(j is JProperty) { JProperty jp = j as JProperty; //读取对象(仅一个配置) AqiConfig ac = createConfigFormJsonObject(jp.Value as JObject); ac.cName = jp.Name; if (ac != null) listConfig.Add(ac); } } } } catch (System.Exception ex) { throw new ConfigException("配置创建错误", ex); } return listConfig; }
/// <summary> /// 读取更新时间 /// 从 JSON 文件 /// </summary> /// <param name="icc">ICacheConfig</param> /// <returns></returns> public static DateTime ReadWriteTimeFormJson(ICacheConfig icc) { try { //JSON路径 string jsonPath = icc.GetJsonFile(); FileInfo fi = new FileInfo(jsonPath); return(fi.LastWriteTime); } catch (System.Exception ex) { throw new ConfigException("读取配置文件错误", ex); } }
public Cache(ISerializer serializer = null, ICacheConfig configuration = null) : base( () => { if (configuration == null) { configuration = CacheConfigSectionHandler.GetConfig(); } if (configuration == null) { throw new ConfigurationErrorsException( "Unable to locate <redisCacheClient> section into your configuration file."); } return(configuration); }, config => { var options = new ConfigurationOptions { Ssl = config.Ssl, AllowAdmin = config.AllowAdmin, Password = config.Password, AbortOnConnectFail = false }; foreach (CacheHost redisHost in config.RedisHosts) { Monitor.Enter(LockForAddingEndpoints); try { options.EndPoints.Add(redisHost.Host, redisHost.CachePort); } finally { Monitor.Exit(LockForAddingEndpoints); } } var connectionMultiplexer = ConnectionMultiplexer.Connect(options); return(connectionMultiplexer); }, (config, connectionMultiplexer) => { var database = connectionMultiplexer.GetDatabase(config.Database); return(database); }, serializer) { }
public ServiceBusChannel(ICacheConfig cacheConfig, ICacheLogger logger) { _cacheConfig = cacheConfig; _cacheLogger = logger; _managementClient = new ManagementClient(_cacheConfig.ServiceBusConnectionString); if (_managementClient.TopicExistsAsync(_cacheConfig.CacheBackPlaneChannel).GetAwaiter().GetResult() == false) { _managementClient.CreateTopicAsync(_cacheConfig.CacheBackPlaneChannel); } if (_managementClient.SubscriptionExistsAsync(_cacheConfig.CacheBackPlaneChannel, _cacheConfig.ListenerInstanceId).GetAwaiter().GetResult() == false) { _managementClient.CreateSubscriptionAsync(_cacheConfig.CacheBackPlaneChannel, _cacheConfig.ListenerInstanceId); } _topicClient = new TopicClient(_cacheConfig.ServiceBusConnectionString, _cacheConfig.CacheBackPlaneChannel, _cacheConfig.RetryPolicy); _taskPool = new ConcurrentDictionary <string, Task>(); }
public CommunicationChannelFactory(ICacheConfig cacheConfig, ICacheLogger logger) { this._cacheConfig = cacheConfig; this._cacheLogger = logger; this.channelCollection = new List <ICommunicationChannel>(); if (this._cacheConfig.IsRabbitCommnunicationChannelEnabled) { RmqChannel item = new RmqChannel(this._cacheConfig, this._cacheLogger); item.Subscribe(); this.channelCollection.Add(item); } if (this._cacheConfig.IsServiceBusCommnunicationChannelEnabled) { ServiceBusChannel item1 = new ServiceBusChannel(this._cacheConfig, this._cacheLogger); item1.Subscribe(); this.channelCollection.Add(item1); } }
public CacheProviderV1(IStoreCollectionProvider <T> storeCollectionProvider, ICacheConfig cacheConfig, IBackPlane backPlane, ICacheLogger logger, IBaseCacheContextManager cacheContextManager) { this._cacheLogger = logger; this._cacheContextManager = cacheContextManager; this._cacheStoreCollection = storeCollectionProvider.GetCacheStoreCollection(); this.minStoreIndex = 0; this.maxStoreIndex = this._cacheStoreCollection.Count; this._cacheConfig = cacheConfig; this.FilterName = typeof(T).FullName; this._backPlane = backPlane; this._nonLockingRuntimeWrapperForCallBacks = new NonLockingRuntimeWrapper <T>(this._cacheLogger); if (this._cacheConfig.BackPlaneEnabled) { this._backPlane.SubscribeToBackPlanEvents <T>(this.FilterName, this.OnBackPlaneEvent); } this._cacheLogger = logger; }
/* * Process处理函数应该保持线程安全 * Runner下的多个Timer会调用此Runner的处理函数 * * */ /// <summary> /// 路由处理 /// 应该由Timer线程调用,可能会嵌套 /// 再此方法中调用的方法应保证线程安全 /// </summary> /// <param name="isu">数据接口</param> /// <param name="sugt">定时器,用于堵塞</param> public void RouteProcess(ISrcUrl isu, SrcUrlGroupTimer sugt) { //加载配置 if (isu.IAW is ICacheConfig) { ICacheConfig icc = isu.IAW as ICacheConfig; if (!icc.IsSrcUrlEnabled(isu.Tag)) { return; } } //双向确认是否使用参数 if (isu.UseParam && isu is ISrcUrlParam) { this.GetProcess(isu as ISrcUrlParam, sugt); } else { this.GetProcess(isu, sugt); } }
public RmqChannel(ICacheConfig cacheConfig, ICacheLogger logger) { this._cacheConfig = cacheConfig; this._cacheLogger = logger; this._connectionFactory = new ConnectionFactory() { HostName = cacheConfig.RabbitConnection.HostName, UserName = cacheConfig.RabbitConnection.UserName, Password = cacheConfig.RabbitConnection.Password, Port = cacheConfig.RabbitConnection.Port, VirtualHost = cacheConfig.RabbitConnection.VirtualHost }; if (this._cacheConfig.RabbitConnection.IsSSlEnabled) { SslOption sslOption = new SslOption { Enabled = true, ServerName = cacheConfig.RabbitConnection.HostName, AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors, }; this._connectionFactory.Ssl = sslOption; } this._connection = this._connectionFactory.CreateConnection(); this._subscriptionClient = this._connection.CreateModel(); this._subscriptionClient.QueueDeclare(queue: this._cacheConfig.ListenerInstanceId, durable: false, exclusive: false, autoDelete: false); this._eventingBasicConsumer = new EventingBasicConsumer(this._subscriptionClient); this._topicClient = this._connection.CreateModel(); this._topicClient.ExchangeDeclare(exchange: this._cacheConfig.CacheBackPlaneChannel, type: "fanout", durable: false, autoDelete: false); }
public BaseBackPlane(ICommunicationChannelFactory channelFactory, ICacheLogger logger, ICacheConfig cacheConfig) { this._cacheLogger = logger; this._cacheConfig = cacheConfig; this.ListenerInstanceId = this._cacheConfig.ListenerInstanceId; this._channels = new ConcurrentDictionary <string, ICommunicationChannel>(); this._onEventHandlers = new ConcurrentDictionary <string, ConcurrentDictionary <string, Action <EventMessage> > >(); if (_cacheConfig.BackPlaneEnabled == true) { foreach (ICommunicationChannel item in channelFactory.GetActiveChannels()) { if (this._channels.TryAdd(item.ChannelUid, item)) { this._channels[item.ChannelUid].OnMessage = this.OnEvent; this._cacheLogger.LogAsync($"Bindng to Communication Channel {item.ChannelUid} Completed", EventLevel.Verbose); } else { this._cacheLogger.LogAsync($"Bindng to Communication Channel {item.ChannelUid} Failed", EventLevel.Error); } } } this._cacheLogger.LogAsync("Bindng to Communication Channels Completed", EventLevel.Verbose); }
/// <summary> /// 初始化基缓存管理器 /// </summary> /// <param name="config">缓存配置</param> public DefaultCacheManager(ICacheConfig config) : base(config) { }
/// <summary> /// 初始化基缓存管理器 /// </summary> /// <param name="config">缓存配置</param> protected CacheManagerBase(ICacheConfig config) : this(config.GetProvider(), config.GetKey()) { }
/// <summary> /// 获取缓存中的本地数据,如果缓存中缺少数据,则回调RecallDataFromLocal事件的数据 /// </summary> /// <returns></returns> public static List <T> GetCacheList <T>(this IServiceXCache pInterface, RecallDataFromLocal <T> pdelegate, ICacheConfig pCacheConfig, CacheItemRemovedCallback RemovedCallback) { object objValue = GetCache(pInterface, pCacheConfig); if (objValue == null || objValue.GetType() != typeof(List <T>)) { var pValue = pdelegate(); if (pValue != null) { if (pValue is IEnumerable <T> ) { if ((pValue as IEnumerable <T>).Count() > 0) { //将缓存内容写入执行项中 pCacheConfig.CacheContent = pValue; //每次从数据库中获取数据都添加到缓存中 pInterface.InsertCache(pCacheConfig, RemovedCallback); } } else { //将缓存内容写入执行项中 pCacheConfig.CacheContent = pValue; //每次从数据库中获取数据都添加到缓存中 pInterface.InsertCache(pCacheConfig, RemovedCallback); } } return(pValue); } return(objValue as List <T>); }
public CacheHandler(IMemoryCache cache, ICacheConfig <TRequest> cacheConfig) { _cache = cache; _cacheConfig = cacheConfig; }
/// <summary> /// 获取缓存 /// </summary> /// <param name="pInterface"></param> /// <param name="pCacheConfig"></param> /// <returns></returns> public static object GetCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig) { return(HttpRuntime.Cache.Get(pCacheConfig.CacheTypeName)); }
/// <summary> /// 获取缓存中的本地数据,如果缓存中缺少数据,则回调RecallDataFromLocal事件的数据 /// </summary> /// <returns></returns> public static List <T> GetCacheList <T>(this IServiceXCache pInterface, RecallDataFromLocal <T> pdelegate, ICacheConfig pCacheConfig) { object objValue = GetCache(pInterface, pCacheConfig); if (objValue == null || objValue.GetType() != typeof(List <T>)) { return(pdelegate()); } return(objValue as List <T>); }
/// <summary> /// 插入缓存,覆盖旧有缓存 /// </summary> /// <param name="pInterface"></param> /// <param name="pCacheConfig"></param> /// <param name="onRemove"></param> public static void InsertCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig, CacheItemRemovedCallback onRemove) { HttpRuntime.Cache.Insert(pCacheConfig.CacheTypeName, pCacheConfig.CacheContent, pCacheConfig.Dependency, pCacheConfig.AbsoluteTime, pCacheConfig.SlidingTime, pCacheConfig.Priority, onRemove); }
/// <summary> /// 清空缓存 /// </summary> /// <param name="pInterface"></param> /// <param name="pCacheConfig"></param> public static void RemoveCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig) { HttpRuntime.Cache.Remove(pCacheConfig.CacheTypeName); }
public LocalCacheManager(ICacheConfig config) : base(config) { }
/// <summary> /// 读取更新时间 /// 从 JSON 文件 /// </summary> /// <param name="icc">ICacheConfig</param> /// <returns></returns> public static DateTime ReadWriteTimeFormJson(ICacheConfig icc) { try { //JSON路径 string jsonPath = icc.GetJsonFile(); FileInfo fi = new FileInfo(jsonPath); return fi.LastWriteTime; } catch (System.Exception ex) { throw new ConfigException("读取配置文件错误", ex); } }
public InMemStore(ICacheConfig cacheConfig, ICacheLogger cacheLogger) { this._cacheConfig = cacheConfig; this._cacheLogger = cacheLogger; }
public RedisFactory(ICacheConfig cacheConfig) => this._cacheConfig = cacheConfig;
public RemoveProjectCache(ICacheConfig <GetProjectCachingQuery> cacheConfig, IMemoryCache cache) { _cacheConfig = cacheConfig; _cache = cache; }
private static IServiceCollection AddAssemblyDependentServices(this IServiceCollection services, Assembly assembly, ICacheConfig cacheConfig) => services .AddLoaders(assembly) .AddCaches(assembly, cacheConfig);
public CacheRegistry(ICacheConfig config) { _config = config; }