/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/csharp/csharp-505-47-004/main.cs
22 строки
674 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
[HttpGet("{id}")] public async Task<ActionResult<Product>> GetProduct(int id) { var redis = HttpContext.RequestServices.GetRequiredService<IConnectionMultiplexer>(); var cache = redis.GetDatabase(); var cached = await cache.StringGetAsync($"product:{id}"); if (!cached.IsNullOrEmpty) { var product = JsonSerializer.Deserialize<Product>(cached!); return Ok(product); } var product = await _context.Products.FindAsync(id); if (product == null) return NotFound(); var json = JsonSerializer.Serialize(product); await cache.StringSetAsync($"product:{id}", json, TimeSpan.FromMinutes(10)); return product; }