Example #1
0
 public BagsController(ILogger <BagsController> logger, IGenericCacheService cache, BagContext context,
                       IWebHostEnvironment environment)
 {
     _logger             = logger;
     _cache              = cache;
     _context            = context;
     _webHostEnvironment = environment;
 }
 public AccountController(UserManager <IdentityUser> userManager,
                          SignInManager <IdentityUser> signInManager,
                          IGenericCacheService cache, BagContext context)
 {
     this.userManager   = userManager;
     this.signInManager = signInManager;
     _cache             = cache;
     _context           = context;
 }
Example #3
0
 public CategoryController(
     IDictionaryService dictionaryService,
     IGenericCacheService <byte[]> cacheImage,
     IMapper mapper)
 {
     _dictionaryService = dictionaryService;
     _cacheImage        = cacheImage;
     _mapper            = mapper;
 }
        public async Task InvokeAsync(HttpContext context, IGenericCacheService <byte[]> cache)
        {
            Stream originalBody = context.Response.Body;

            if (context.Request.Path.ToString()
                .ToLower().Contains("image"))
            {
                var key   = context.Request.Path.ToString();
                var image = await cache.GetEntityAsync(key);

                if (image != null)
                {
                    context.Response.ContentType = "image/png";
                    await context.Response.Body.WriteAsync(image);

                    return;
                }
            }

            try
            {
                using (var memStream = new MemoryStream())
                {
                    context.Response.Body = memStream;

                    await _next(context);

                    memStream.Position = 0;
                    await memStream.CopyToAsync(originalBody);

                    if (context.Response.StatusCode == (int)HttpStatusCode.OK &&
                        context.Response.ContentType == "image/png")
                    {
                        try
                        {
                            memStream.Position = 0;
                            var responseBody = memStream.GetBuffer();

                            await cache.SetEntityAsync(context.Request.Path.ToString(), responseBody);
                        }
                        catch (System.Exception ex)
                        {
                            throw new System.Exception("Error writing response form cache", ex);
                        }
                    }
                }
            }
            finally
            {
                context.Response.Body = originalBody;
            }
        }
Example #5
0
 public LinksController(ILogger <LinksController> logger, IGenericCacheService cache, BagContext context)
 {
     _logger  = logger;
     _cache   = cache;
     _context = context;
 }