public IActionResult Get([FromQuery] string imageName) { byte[] image = _cacheHelper.ProcessCache(imageName); if (image is null) { image = _client.GetImage(); } return(new FileContentResult(image, ContentTypes.Jpeg)); }
public IActionResult Get() { var cacheKey = $"image_{DateTime.UtcNow.Date}"; var image = _cache.Get <byte[]>(cacheKey); if (image is null) { image = _client.GetImage(); var options = new MemoryCacheEntryOptions(); options.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(30); _cache.Set <byte[]>(cacheKey, image, options); } return(new FileContentResult(image, "image/jpeg")); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var cacheKey = $"image_{DateTime.UtcNow.Date}"; var callInterval = TimeSpan.FromMinutes(2); var image = _client.GetImage(); var options = new MemoryCacheEntryOptions(); options.AbsoluteExpirationRelativeToNow = callInterval; _cache.Set <byte[]>(cacheKey, image, options); await Task.Delay(callInterval); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var imageName = _configuration.ImageName; var callInterval = TimeSpan.FromMinutes(2); byte[] image = _cacheHelper.ProcessCache(imageName); if (image is null) { image = _client.GetImage(); } await Task.Delay(callInterval); // Recieve information about the image to get // Check if image is in cache // Get image from ExternalImageServiceClient // Add image to cache (if it was fetched) // Return image } }