1

I have blob data's approx 85000 images i am generating it from handler and stored in to database as image datatype now when i render it into a webpage it working very slow obviously so i want to find some middle solution for this one probably cache i think its a best solution for me so can any one give me some idea about this one my code looks like this

public void ProcessRequest(HttpContext context)
    {

context.Response.OutputStream.Write(buffer, 0, byteSeq);
                byteSeq = strm.Read(buffer, 0, 8192);
}

and image

     <img  src='<%# "handler/product?"+Email.Encryptdes(DataBinder.Eval(Container.DataItem,"product_id").ToString()) %>'/>

so what to do now i can not see my page loading at 30 seconds Should i go for folder option for images?

Just code
  • 13,553
  • 10
  • 51
  • 93
  • 1
    Is it required to store images in DB? I would say better you store images in some folder and put that path in DB. This will also reduce your DB size and number of requests you are making to DB. – alok_dida Nov 14 '13 at 04:30
  • 1
    I agree with alok_dida plus caching will not avoid the initial page load performance hit. – IrishChieftain Nov 14 '13 at 04:34
  • Ya i know @alok_dida but myproblem is i have to revert all the things that would be messy so i am finding some middlest option i know folder option is best but is that only option remains for me? – Just code Nov 14 '13 at 04:43
  • Ya @IrishChieftain but what to do now? – Just code Nov 14 '13 at 04:45
  • Check some of the answers here: http://stackoverflow.com/questions/3720046/setting-httphandler-isreusable-property/3720129#3720129 but it would help if you could narrow down the problem. If your images are all big then it may not be the SQL query. Are you loading images into a ListView or such? If so, then set page size to something less, etc... – IrishChieftain Nov 14 '13 at 04:50
  • I am using repeater control for this one – Just code Nov 14 '13 at 04:52
  • How many images are you loading up on page load and what's the average image size? – IrishChieftain Nov 14 '13 at 04:54
  • Avg image size is 80kb i am showing 30images on page load – Just code Nov 14 '13 at 04:55
  • 1
    That's contributing to it. Images alone are 2.4 MB plus rest of page overhead. Reduce page size to 10 and check the difference? (Empty your cache between each attempt). – IrishChieftain Nov 14 '13 at 04:58
  • Ok @IrishChieftain i am replying you after checking – Just code Nov 14 '13 at 05:00

2 Answers2

4

You can set cache in the handler itself as follows

context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(10));

So if the browser ask for the same data it is cached for 10 minutes.

For further improvement you can save the image in a local folder and then set the path.

Few useful links

  1. How to use output caching on .ashx handler
  2. Cache an object in a .ashx handler
  3. How to server-side cache ASP.NET custom HttpHandler response
Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • Thanks for reply shekhar i would like one more little help is there anyway to automatically tell browser to update this image incase user change image then what to do? – Just code Nov 14 '13 at 04:44
  • @dholakiyaankit you can create use server side cache if it is in server cache then provide else create a cache and then provide the cache (on the basis of query string or any other condition). Set the cache expire time as feasible. – शेखर Nov 14 '13 at 05:56
1

Your best approach is to store the images in folders and the paths in the database.

Next option would be to check overall size of images being downloaded on one page load. Try reducing this to at most, about 10 images; set page size of your Repeater to 10.

You can also add caching but this will not in any way help speed up the first page load for everyone that comes to your site, and it is the first impressions that count.

Finally, set IsReusable property of your handler to false unless you're defensively coding against possibility of multi-threading issues.

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91