2009-07-29 2 views
0

양식 당 50 회 이상 호출하고 있으므로 클라이언트 측에서 어떻게 이미지를 캐싱 할 수 있습니까?데이터베이스에서 캐시 된 동적 생성 이미지

새로 고침마다 데이터베이스를 호출하고 조회합니다.

<%@ WebHandler Language="C#" %> 

using System; 
using System.Web; 
using System.Data.SqlClient; 
using App_Code.BLL.Products; 

public class ProductPicture : IHttpHandler 
{ 
    private Product _objProducts; 
    private ProductBL _objProductBL; 

    #region IHttpHandler Members 

    public void ProcessRequest(HttpContext context) 
    { 
     string strSize = context.Request.QueryString["PhotoType"]; 
     _objProducts = new Product(); 
     _objProductBL = new ProductBL(); 

     _objProducts.PictureID = Convert.ToInt32(context.Request.QueryString["PhotoId"]); 
     SqlDataReader objReaderPhoto = _objProductBL.GetPictureByPictureID(_objProducts); 
     if (!objReaderPhoto.HasRows) return; 
     objReaderPhoto.Read(); 
     context.Response.ContentType = "Image/JPEG"; //Convert.ToString(objReaderPhoto["Photograph"]); 
     context.Response.AddHeader("Content-Disposition", "attachment; filename=Image"); 
     switch (strSize) 
     { 
      case "m": 
       context.Response.BinaryWrite((byte[])objReaderPhoto["PictureBinary"]); 
       break; 
      //case "s": 
      // context.Response.BinaryWrite((byte[]) objReaderPhoto["PhotoSearch"]); 
      // break; 
      case "t": 
       context.Response.BinaryWrite((byte[])objReaderPhoto["PictureThumbnail"]); 
       break; 
      default: 
       context.Response.BinaryWrite((byte[])objReaderPhoto["PictureBinary"]); 
       break; 
     } 

     context.Response.Cache.SetLastModified(DateTime.Now.AddYears(-1)); 

     objReaderPhoto.Close(); 
    } 

    public bool IsReusable { 
     get { 
      return false; 
     } 
    } 

    #endregion 
} 

답변

2

나는 그것이 URL "IMG/someimage.gif"을하지 않는 한 당신은 클라이언트 측에서 그것을 캐시 할 수 있다고 생각하지 않는다, 어떤 HttpContext를 캐시에 그 결과를 캐시에 대해? 조금만 도와주세요. Cache

관련 문제