Ejemplo n.º 1
0
        public FileContentResult Get(string imageName)
        {
            byte[] image = _loadFile.GetImage(imageName);

            if (image == null)
            {
                image = _restClient.GetFile(imageName);
                _loadFile.CacheSet(image, imageName);
            }

            return(new FileContentResult(image, "image/jpeg"));
        }
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                var cacheKey = $"image_{DateTime.UtcNow:yyyy_mm_dd}";
                var image    = _cache.Get <byte[]>(cacheKey);

                if (image == null)
                {
                    image = _restClient.GetFile();
                    var memoryCacheEntry = new MemoryCacheEntryOptions();
                    memoryCacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(2);
                    _cache.Set <byte[]>(cacheKey, image, memoryCacheEntry);
                }

                await Task.Delay(TimeSpan.FromMinutes(2));
            }
        }