예제 #1
0
        public async Task Create <T>(string table, T model)
        {
            var response = await _redisContext.Get <ICollection <T> >(table);

            if (response == null)
            {
                response = Activator.CreateInstance <List <T> >();
            }
            response.Add(model);
            await _redisContext.Add(table, response);
        }
예제 #2
0
        public ActionResult <List <Customer> > GetsWithRedis()
        {
            byte[] bytes = default(byte[]);
            HttpContext.Session.TryGetValue("UserFullName", out bytes);
            string userFullName = Encoding.UTF8.GetString(bytes);

            List <Customer> customerList = _customerRedisManager.Get <List <Customer> >("customers");

            return(customerList);
        }
        internal async Task <TSource> GetFromCacheIfExist <TSource>(string cacheKey, Func <Task <TSource> > callBack)
        {
            var items = _redisContext.Get <TSource>(cacheKey);

            if (items == null)
            {
                items = await callBack();

                SaveOnCache(cacheKey, items);
            }

            return(items);
        }
        public async Task <IActionResult> Find([FromRoute] string id)
        {
            var cacheKey = $"{CacheKeys.Routes}:{id}";

            var routePath = _redisContext.Get <BestRoutePath>(cacheKey);

            if (routePath is null)
            {
                var result = await _mediator.Send(new FindTheBestRoutePathCommand(id));

                if (result.Success is false)
                {
                    return(Error(result.ErrorMessage));
                }

                routePath = result.Value;

                _routeReadOnlyRepository.SaveOnCache(cacheKey, routePath);
            }

            return(Success(routePath));
        }