public async Task Initialize(string url, string hub) { try { if (this.hubConnection == null || this.hubConnection.State == HubConnectionState.Disconnected) { this.hubConnection = new HubConnectionBuilder() .WithUrl(url) .Build(); this.hubConnection.On <ResponseModel>("statusRelayUpdate", (model) => { if (this.Update != null) { this.Update(model); } }); await hubConnection.StartAsync(); } } catch (Exception ex) { Trace.TraceError(ex.Message); if (this.hubConnection != null) { this.hubConnection.StopAsync().Wait(); this.hubConnection = null; } } try { if (this.Cache == null) { //RedisCacheOptions options = new RedisCacheOptions(); //options.ConfigurationOptions = StackExchange.Redis.ConfigurationOptions.Parse(config["RedisConnectionString"]); //IDistributedCache dc = new RedisCache(options); BlobAsyncDistributedCache <ResponseModel> dc = new BlobAsyncDistributedCache <ResponseModel>( this.config); this.Cache = new StatusCache(dc); } } catch (Exception ex) { Trace.TraceError(ex.Message); if (this.Cache != null) { this.Cache.Dispose(); this.Cache = null; } } }
public async Task GetCachedModel() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); BlobAsyncDistributedCache <ResponseModel> dc = new BlobAsyncDistributedCache <ResponseModel>( config); StatusCache cache = new StatusCache(dc); ResponseModel model = await cache.GetAsync("999"); }
public async Task SetCachedModel() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); BlobAsyncDistributedCache <ResponseModel> dc = new BlobAsyncDistributedCache <ResponseModel>( config); StatusCache cache = new StatusCache(dc); ResponseModel model = new ResponseModel(); model.Id = "999"; model.Percent = 50; await cache.SetAsync(model); }