Exemplo n.º 1
0
        public ProductDTO GetProduct(int id)
        {
            if (HttpContext.Current.Cache[keyPrefixProductId + id] != null)
            {
                return((ProductDTO)HttpContext.Current.Cache[keyPrefixProductId + id]);
            }

            Product p = ProductManage.Get(id);

            if (p == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            ProductDTO mpd = new ProductDTO
            {
                ProductId      = p.ProductId,
                ProductName    = p.ProductName,
                ProductSEOName = p.ProductSEOName,
                Category       = p.Category,
                Discount       = p.Discount,
                Tax            = p.Tax,
                Shipping       = p.Shipping,
                ProductPrice   = p.ProductPrice,
                ProductCount   = p.ProductCount,
                Status         = p.Status,
                ImagePath      = p.ImagePath
            };

            //HttpContext.Current.Cache[keyPrefixProductId + id] = mpd;

            HttpContext.Current.Cache.Insert(keyPrefixProductId + id, mpd, null,
                                             DateTime.Now.ToUniversalTime().AddMinutes(5),
                                             Cache.NoSlidingExpiration);
            return(mpd);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获得详细信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static ProductInfo Get(int id)
 {
     return(ProductManage.Get(id));
 }