views:

129

answers:

1

Since we are calling more then 50 times per form. How can I able to cache the images in client side.

For each refresh it called and hits the database.

<%@ 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  A: 

I don't think you can cache it on the client side unless it has a url "img/someimage.gif", what about caching the results in the HttpContext cache? A little help on Cache

TWith2Sugars