示例#1
0
        public async Task <IActionResult> GetAllCartItemsAsync(string?recordKey = null)//IEnumerable<CartItems>
        {
            if (string.IsNullOrEmpty(recordKey))
            {
                var cartItems = await _cartItemsService.GetAllCartItemsAsync();

                var cartItemsDTO = _mapper.Map <IEnumerable <CartItemsDTO> >(cartItems);
                return(Ok(cartItemsDTO));
            }

            var casheItem = await _cacheService.GetRecordAsync <IEnumerable <CartItemsDTO> >(recordKey);

            if (casheItem == null)
            {
                var cartItems = await _cartItemsService.GetAllCartItemsAsync();

                var cartItemsDTO = _mapper.Map <IEnumerable <CartItemsDTO> >(cartItems);
                await _cacheService.SetRecordAsync <IEnumerable <CartItemsDTO> >(recordKey, cartItemsDTO, TimeSpan.FromSeconds(3600));
            }

            return(Ok(casheItem));
        }