public async Task<ActionResult<ProductDto>> Get([FromRoute] int id) { if (id == 0) { return Conflict(); } var product = LazyRedis.Get<ProductDto>(id.ToString()); if (product == null) { var result = await _readApiClient.GetProduct(id); if (result.ProductId == 0) return NotFound("Product not found"); LazyRedis.Add($"Product_{id}", result, TimeSpan.FromMinutes(30)); return Ok(result); } else { return Ok(product); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCustomLogger(env, Configuration); Log.ForContext <Startup>() .Information("<{EventID:l}> Configure Started {Application} with {@configuration}", "Startup", env.ApplicationName, Configuration); LazyRedis.InitializeConnectionString($"{Configuration.GetConnectionString("Redis")},abortConnect=false"); LazyRedis.DefaultDb = int.Parse(Configuration.GetConnectionString("RedisDb")); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(x => { x.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); x.RoutePrefix = string.Empty; }); app.UseMvc(); }