/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="optionsAccs">Options accs.</param> /// <param name="factory">Providers factory</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( string name , HybridCachingOptions optionsAccs , IEasyCachingProviderFactory factory , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNull(factory, nameof(factory)); this._name = name; this._options = optionsAccs; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); if (optionsAccs.EnableLogging) { this._logger = loggerFactory.CreateLogger <HybridCachingProvider>(); } // Here use the order to distinguish traditional provider this._localCache = factory.GetCachingProvider(_options.LocalCacheProviderName); // Here use the order to distinguish traditional provider this._distributedCache = factory.GetCachingProvider(_options.DistributedCacheProviderName); this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); }
/// <summary> /// </summary> /// <returns> /// </returns> public async Task <IActionResult> IndexAsync() { await _hub.Clients.User(_iUserInfo.UserId).SendAsync("welcome", "欢迎您访问系统"); //用户数量 ViewBag.SysUserCount = await userManager.Users.CountAsync(); // 系统使用次数 ViewBag.shiyong = await _iSysUserLogService.GetAll().CountAsync(); //执行速度 ViewBag.SysUserLogDayDuration = _iDapperRepository.QueryAsync("select * from (SELECT top 10 'Keys'=CAST(createddatetime AS DATE ),'Value'=CEILING(AVG(Duration)) FROM sysuserlogs GROUP BY CAST(createddatetime AS DATE ) order by keys desc) as temp order by keys").Result.ToDictionary(a => a.Keys.ToShortDateString(), b => b.Value); //使用次数 曲线图 ViewBag.SysUserLogDayCount = _iDapperRepository.QueryAsync("select * from (SELECT top 10 'Keys'=CAST(createddatetime AS DATE ),'Value'=COUNT(*) FROM sysuserlogs GROUP BY CAST(createddatetime AS DATE ) order by keys desc) as temp order by keys;").Result.ToDictionary(a => a.Keys.ToShortDateString(), b => b.Value); //当前访问的数据库大小 ViewBag.DbSize = _iDapperRepository.QueryAsync($"sp_spaceused").Result.FirstOrDefault()?.database_size.ToString(); //当前用户未读消息数量 ViewBag.MessageUnread = await _iSysMessageCenterService.GetAll(a => (a.AddresseeId == null || a.AddresseeId.Contains(_iUserInfo.UserId)) && a.SysMessageReceiveds.All(b => b.CreatedBy != _iUserInfo.UserId)).CountAsync(); ViewBag.CacheCountInMemory = await _IEasyCachingProviderFactory.GetCachingProvider(EasyCachingConstValue.DefaultInMemoryName).GetCountAsync(); ViewBag.CacheCountRedis = await _IEasyCachingProviderFactory.GetCachingProvider(EasyCachingConstValue.DefaultRedisName).GetCountAsync(); return(View()); }
public string Get(string name = EasyCachingConstValue.DefaultInMemoryName) { var provider = _factory.GetCachingProvider(name); var val = name.Equals("cus") ? "cus" : "default"; var res = provider.Get("demo", () => val, TimeSpan.FromMinutes(1)); return($"cached value : {res}"); }
public CheckHisotryService(ILoggerFactory loggerFactory , IEasyCachingProviderFactory factory) { _logger = loggerFactory.CreateLogger <CheckHisotryService>(); _factory = factory; _memoryProvider = _factory.GetCachingProvider(EasyCachingConstValue.DefaultInMemoryName); _redisProvider = _factory.GetCachingProvider(EasyCachingConstValue.DefaultCSRedisName); }
public HybridCachingTest() { _namespace = "hybrid"; IServiceCollection services = new ServiceCollection(); services.AddEasyCaching(option => { option.UseInMemory("m1"); option.UseInMemory("m2"); option.UseRedis(config => { config.DBConfig.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379)); config.DBConfig.Database = 5; }, "myredis"); option.WithRedisBus(config => { config.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379)); config.Database = 6; }); }); IServiceProvider serviceProvider = services.BuildServiceProvider(); factory = serviceProvider.GetService <IEasyCachingProviderFactory>(); var providers_1 = new List <IEasyCachingProvider> { factory.GetCachingProvider("m1"), factory.GetCachingProvider("myredis") }; var providers_2 = new List <IEasyCachingProvider> { factory.GetCachingProvider("m2"), factory.GetCachingProvider("myredis") }; var bus = serviceProvider.GetService <IEasyCachingBus>(); hybridCaching_1 = new HybridCachingProvider(new OptionsWrapper <HybridCachingOptions>(new HybridCachingOptions { EnableLogging = false, TopicName = "test_topic" }), providers_1, bus); hybridCaching_2 = new HybridCachingProvider(new OptionsWrapper <HybridCachingOptions>(new HybridCachingOptions { EnableLogging = false, TopicName = "test_topic" }), providers_2, bus); }
public IActionResult Set() { var cache1 = _easyCachingProviderFactory.GetCachingProvider("csredis"); var cache2 = _easyCachingProviderFactory.GetCachingProvider("default"); cache1.Set("testcs", 1, TimeSpan.FromSeconds(500)); cache2.Set("testde", "testde", TimeSpan.FromSeconds(500)); return(new JsonResult(new { Data = "设置成功" })); }
public DeptAppService(IMapper mapper , IHybridProviderFactory hybridProviderFactory , IEasyCachingProviderFactory simpleProviderFactory , IEfRepository <SysDept> deptRepository , ISystemManagerService systemManagerService) { _mapper = mapper; _cache = hybridProviderFactory.GetHybridCachingProvider(EasyCachingConsts.HybridCaching); _locaCahce = simpleProviderFactory.GetCachingProvider(EasyCachingConsts.LocalCaching); _redisCache = simpleProviderFactory.GetCachingProvider(EasyCachingConsts.RemoteCaching); _deptRepository = deptRepository; _systemManagerService = systemManagerService; }
public void NamedSerializerTest() { var se1 = _providerFactory.GetCachingProvider("se1"); var se2 = _providerFactory.GetCachingProvider("se2"); var se3 = _providerFactory.GetCachingProvider("se3"); var info1 = se1.GetProviderInfo(); var info2 = se2.GetProviderInfo(); var info3 = se3.GetProviderInfo(); Assert.Equal("cs11", info1.Serializer.Name); Assert.Equal("se2", info2.Serializer.Name); Assert.Equal(EasyCachingConstValue.DefaultSerializerName, info3.Serializer.Name); }
public async Task <ActionResult <Car> > GetCar(int id) { var cache = _easyCachingProviderFactory.GetCachingProvider("default"); var car = await cache.GetAsync($"car{id}", async() => await _context.Cars.FindAsync(id), TimeSpan.FromSeconds(60)); //var car = await _context.Cars.FindAsync(id); if (car == null) { return(NotFound()); } return(Ok(car)); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.ResponseCaching.EasyCachingResponseCache"/> class. /// </summary> /// <param name="name">Provider Name</param> /// <param name="providerFactory">Provider factory</param> public EasyCachingResponseCache(string name, IEasyCachingProviderFactory providerFactory) { ArgumentCheck.NotNull(providerFactory, nameof(providerFactory)); _provider = providerFactory.GetCachingProvider(name); }
public void KeyPrefixTest() { var NotKeyPrefix = _providerFactory.GetCachingProvider("NotKeyPrefix"); var WithKeyPrefix = _providerFactory.GetCachingProvider("WithKeyPrefix"); WithKeyPrefix.Set("KeyPrefix", "ok", TimeSpan.FromSeconds(10)); var val1 = NotKeyPrefix.Get <string>("foo:" + "KeyPrefix"); var val2 = WithKeyPrefix.Get <string>("foo:" + "KeyPrefix"); Assert.NotEqual(val1.Value, val2.Value); var val3 = WithKeyPrefix.Get <string>("KeyPrefix"); Assert.Equal(val1.Value, val3.Value); }
private async Task RefreshAsync() { _logger.LogInformation($"Refresh caching begin at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); try { var cachingProvider = _providerFactory.GetCachingProvider("m1"); // mock query data from database or others var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var random = new Random().NextDouble(); // only once var dict = new Dictionary <string, string>() { { ConstValue.Time_Cache_Key, time }, { ConstValue.Random_Cache_Key, random.ToString() } }; await cachingProvider.SetAllAsync(dict, TimeSpan.FromDays(30)); //// one by one //await cachingProvider.SetAsync(Time_Cache_Key, time, TimeSpan.FromSeconds(10)); //await cachingProvider.SetAsync(Random_Cache_Key, random.ToString(), TimeSpan.FromSeconds(10)); } catch (Exception ex) { _logger.LogError(ex, $"Refresh caching error ..."); } _logger.LogInformation($"Refresh caching end at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); }
public MenuAppService(IEfRepository <SysMenu> menuRepository, IEfRepository <SysRelation> relationRepository, IEasyCachingProviderFactory cacheFactory) { _menuRepository = menuRepository; _relationRepository = relationRepository; _cache = cacheFactory.GetCachingProvider(EasyCachingConsts.RemoteCaching); }
public DeptAppService(IEasyCachingProviderFactory cacheFactory , IEfRepository <SysDept> deptRepository , UsrManager usrManager) { _cache = cacheFactory.GetCachingProvider(EasyCachingConsts.RemoteCaching); _deptRepository = deptRepository; _usrManager = usrManager; }
public async Task <IActionResult> GetAsync() { var provider = _providerFactory.GetCachingProvider("m1"); var obj = await provider.GetAsync("mykey", async() => await _dbContext.DemoObjs.ToListAsync(), TimeSpan.FromSeconds(30)); return(Ok(obj)); }
public DictAppService(IEfRepository <SysDict> dictRepository , MaintManager maintManager , IEasyCachingProviderFactory cacheFactory) { _dictRepository = dictRepository; _maintManager = maintManager; _cache = cacheFactory.GetCachingProvider(EasyCachingConsts.RemoteCaching); }
public NacosServerManager( INacosNamingClient client, IEasyCachingProviderFactory factory, IOptions <NacosAspNetCoreOptions> optionsAccs) { _client = client; _provider = factory.GetCachingProvider("nacos.aspnetcore"); }
public RecipeDetailsRepository(IEasyCachingProviderFactory cachingProviderFactory, IMediator mediator, IRecipeDetailsMapper recipeDetailsMapper, IFilterFactory <RecipeDetails, RecipeSearchFilterCriteria> filterFactory) { _mediator = mediator; _recipeDetailsMapper = recipeDetailsMapper; _filterFactory = filterFactory; _cachingProvider = cachingProviderFactory.GetCachingProvider(RedisConstants.Name); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="optionsAccs">Options accs.</param> /// <param name="IEasyCachingProviderFactory">Providers factory</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( IOptions <HybridCachingOptions> optionsAccs , IEasyCachingProviderFactory factory , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNull(factory, nameof(factory)); this._options = optionsAccs.Value; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); this._logger = loggerFactory?.CreateLogger <HybridCachingProvider>(); //Here use the order to distinguish traditional provider var local = factory.GetCachingProvider(_options.LocalCacheProviderName); if (local.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any local caching providers."); } else { this._localCache = local; } //Here use the order to distinguish traditional provider var distributed = factory.GetCachingProvider(_options.DistributedCacheProviderName); if (!distributed.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any distributed caching providers."); } else { this._distributedCache = distributed; } this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); }
public CheckDevices(ILogger <CheckDevices> logger, IServiceScopeFactory scopeFactor, IMqttServerEx serverEx , IOptions <AppSettings> options, IEasyCachingProviderFactory factory) { _mcsetting = options.Value.MqttClient; _logger = logger; _scopeFactor = scopeFactor; _factory = factory; _serverEx = serverEx; _device = _factory.GetCachingProvider("iotsharp"); }
public DistributedEasyCaching(IEasyCachingProviderFactory easyCachingProviderFactory, IOptions <DistributedEasyCachingOptions> options) : base(options?.Value ?? throw new ArgumentNullException(nameof(options))) { if (easyCachingProviderFactory == null) { throw new ArgumentNullException(nameof(easyCachingProviderFactory)); } _easyCachingProvider = easyCachingProviderFactory.GetCachingProvider(options.Value.ProviderName); }
/// <summary> /// Using IMemoryCache as a cache service. /// </summary> public EFEasyCachingCoreProvider( IOptions <EFCoreSecondLevelCacheSettings> cacheSettings, IEasyCachingProviderFactory easyCachingProviderFactory, IReaderWriterLockProvider readerWriterLockProvider) { _cacheSettings = cacheSettings?.Value; _readerWriterLockProvider = readerWriterLockProvider; _easyCachingProviderFactory = easyCachingProviderFactory ?? throw new ArgumentNullException("Please register the `EasyCaching.Core`."); _easyCachingProvider = _easyCachingProviderFactory.GetCachingProvider(_cacheSettings.ProviderName); }
public FlowRuleProcessor(ILogger <FlowRuleProcessor> logger, IServiceScopeFactory scopeFactor, IOptions <AppSettings> options, TaskExecutorHelper helper, IEasyCachingProviderFactory factory) { _scopeFactor = scopeFactor; _logger = logger; _setting = options.Value; _allFlows = new List <Flow>(); _allflowoperation = new List <FlowOperation>(); _helper = helper; _caching = factory.GetCachingProvider("iotsharp"); _sp = _scopeFactor.CreateScope().ServiceProvider; }
public EventBusHandler(ILogger <EventBusHandler> logger, IServiceScopeFactory scopeFactor , IOptions <AppSettings> options, IStorage storage, FlowRuleProcessor flowRuleProcessor, IEasyCachingProviderFactory factory ) { _appSettings = options.Value; _logger = logger; _scopeFactor = scopeFactor; _storage = storage; _flowRuleProcessor = flowRuleProcessor; _caching = factory.GetCachingProvider("iotsharp"); }
public NacosServerManager( INacosNamingClient client, IEasyCachingProviderFactory factory, IEnumerable <ILBStrategy> strategies, IOptions <NacosAspNetCoreOptions> optionsAccs) { _client = client; _provider = factory.GetCachingProvider("nacos.aspnetcore"); _strategy = strategies.FirstOrDefault(x => x.Name.ToString().Equals(optionsAccs.Value.LBStrategy, StringComparison.OrdinalIgnoreCase)) ?? new WeightRandomLBStrategy(); }
public AuthController(IUserRepository userRepository, ICryptoService cryptoService, ITokenService tokenService, IOptions <AppSettings> appSettings, IUnitOfWork unitOfWork, IEasyCachingProviderFactory cachingProviderFactory, ICachingService cachingService) { _userRepository = userRepository; _cryptoService = cryptoService; _tokenService = tokenService; _appSettings = appSettings; _unitOfWork = unitOfWork; _cachingProviderFactory = cachingProviderFactory; _cachingService = cachingService; _easyCaching = cachingProviderFactory.GetCachingProvider("redis_naim");; }
public MQTTServerHandler(ILogger <MQTTServerHandler> logger, IServiceScopeFactory scopeFactor, IMqttServerEx serverEx , IOptions <AppSettings> options, ICapPublisher queue, IEasyCachingProviderFactory factory ) { _mcsetting = options.Value.MqttClient; _logger = logger; _scopeFactor = scopeFactor; _factory = factory; _serverEx = serverEx; _queue = queue; _device = _factory.GetCachingProvider("iotsharp"); }
public RoleAppService(IEfRepository <SysRole> roleRepository, IEfRepository <SysUser> userRepository, IEfRepository <SysRelation> relationRepository, UsrManager usrManager, IEasyCachingProviderFactory cacheFactory) { _roleRepository = roleRepository; _userRepository = userRepository; _relationRepository = relationRepository; _usrManager = usrManager; _cache = cacheFactory.GetCachingProvider(EasyCachingConsts.RemoteCaching); }
public ActionResult <IEnumerable <string> > Get() { var provider = _providerFactory.GetCachingProvider("m1"); var time = provider.Get <string>(ConstValue.Time_Cache_Key); // do somethings based on time ... var random = provider.Get <string>(ConstValue.Random_Cache_Key); // do somethings based on random ... return(new string[] { time.Value, random.Value }); }
public OcelotEasyCachingCache( IOptions <OcelotEasyCachingOptions> optionsAccs, IEasyCachingProviderFactory providerFactory, IHybridProviderFactory hybridFactory = null) { _options = optionsAccs.Value; if (!_options.EnableHybrid) { _provider = providerFactory.GetCachingProvider(_options.ProviderName); } else { _hybridProvider = hybridFactory.GetHybridCachingProvider(_options.HybridName); } }