473,799 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cache Images vs Static Images

Hi All,
I have a aspx page named: ImageProcess.as px that creates a thumbnail
version of an image by passing the ImagePath, width, and height. The
ImagePath is taken from a table from a database, while width and
height is user specific - meaning user can change this on demand.

My question is, although this rendering images on the fly is cool, I
would like to implement some sort of mechanism/logic that it wont keep
rendering the thumbnail again and again.

I thought of two things that might solve my problem, however I am
unsure of the pros and cons and which is much faster for the client.

Solution #1: Caching
----------------------------------
using System.Web.Cach ing;
Cache Cache = context.Cache;

//Get the image
string path = Server.MapPath( Request.FilePat h);

//Check the cache
string key = path + "-" + strWidth + "-" strHeight;
if (Cache[key] != null)
{
Image cached = (Image) Cache[key];
cached.Save(Res ponse.OutputStr eam,ImageFormat .Jpeg);
return;
}
else
{
Image img = Image.FromFile( path);

//Add to the cache
Cache.Add(key, thumb, null, DateTime.Now.Ad dSeconds(10),
TimeSpan.Zero, CacheItemPriori ty.High,
new CacheItemRemove dCallback(this. RemovedCallback ));
}

this solution checks if a "Cache Key" exists for a particular ImagePath
+Width+Height combo exsits, then it uses the "Saved Cached Image", if
none, it will use the image directly from the Image.FromFile( path) and
adds a new "Cache Key" for it.
Solution #2: Static Images
----------------------------------
1. Create the static image that was generated on the fly by the
ImageProcess.as px to a directory in the webserver ex: Root
\ThumbnailImage s\
2. The static image will be named as ImagePath-ImageName-ImageWidth-
ImageHeight-ImageDateCreate d.ImageExtensio n

Where
ImagePath = Image's Full Path taken from a table.column in a db
ImageName = Image File Name taken from a table column in a db
ImageWidth = Client User specific
ImageHeight = Client User spefici
ImageDateCreate d = Image Upload DateTime taken from a table.column in
a db.

3. Subsequent request logic will be:
3.1 First check if the combination filename exists in the Root
\ThumbnailImage s\ folder
3.2 If it exist, use that static image
3.2 If it does not exist, create image on the fly using
ImageProcess.as px & create a thumbnail image in the thumbnail Root
\ThumbnailImage s\ folder
I am a bit confuse on which to use. I am after - which is faster ;-)
Lastly, if I use Solution#1: Caching, when the user exists his or her
browser, then opens a new browser, will the "Cache Keys" still be
there? In other words, are the "Cache Keys" stored in the webserver
for use by other concurrent users?

Thanks,
Henry Wu

Jun 14 '07 #1
3 4017

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Solution 2 is better, as it doesn't rely on memory to cache the images.
However, I have one suggestion: You don't need to keep the date created in
the image file name. That is an attribute of the file.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"wardemon" <he***********@ gmail.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
Hi All,
I have a aspx page named: ImageProcess.as px that creates a thumbnail
version of an image by passing the ImagePath, width, and height. The
ImagePath is taken from a table from a database, while width and
height is user specific - meaning user can change this on demand.

My question is, although this rendering images on the fly is cool, I
would like to implement some sort of mechanism/logic that it wont keep
rendering the thumbnail again and again.

I thought of two things that might solve my problem, however I am
unsure of the pros and cons and which is much faster for the client.

Solution #1: Caching
----------------------------------
using System.Web.Cach ing;
Cache Cache = context.Cache;

//Get the image
string path = Server.MapPath( Request.FilePat h);

//Check the cache
string key = path + "-" + strWidth + "-" strHeight;
if (Cache[key] != null)
{
Image cached = (Image) Cache[key];
cached.Save(Res ponse.OutputStr eam,ImageFormat .Jpeg);
return;
}
else
{
Image img = Image.FromFile( path);

//Add to the cache
Cache.Add(key, thumb, null, DateTime.Now.Ad dSeconds(10),
TimeSpan.Zero, CacheItemPriori ty.High,
new CacheItemRemove dCallback(this. RemovedCallback ));
}

this solution checks if a "Cache Key" exists for a particular ImagePath
+Width+Height combo exsits, then it uses the "Saved Cached Image", if
none, it will use the image directly from the Image.FromFile( path) and
adds a new "Cache Key" for it.
Solution #2: Static Images
----------------------------------
1. Create the static image that was generated on the fly by the
ImageProcess.as px to a directory in the webserver ex: Root
\ThumbnailImage s\
2. The static image will be named as ImagePath-ImageName-ImageWidth-
ImageHeight-ImageDateCreate d.ImageExtensio n

Where
ImagePath = Image's Full Path taken from a table.column in a db
ImageName = Image File Name taken from a table column in a db
ImageWidth = Client User specific
ImageHeight = Client User spefici
ImageDateCreate d = Image Upload DateTime taken from a table.column in
a db.

3. Subsequent request logic will be:
3.1 First check if the combination filename exists in the Root
\ThumbnailImage s\ folder
3.2 If it exist, use that static image
3.2 If it does not exist, create image on the fly using
ImageProcess.as px & create a thumbnail image in the thumbnail Root
\ThumbnailImage s\ folder
I am a bit confuse on which to use. I am after - which is faster ;-)
Lastly, if I use Solution#1: Caching, when the user exists his or her
browser, then opens a new browser, will the "Cache Keys" still be
there? In other words, are the "Cache Keys" stored in the webserver
for use by other concurrent users?

Thanks,
Henry Wu

Jun 14 '07 #2
Hi Kevin,
Thanks for you reply. I'll do solution 2 then.

Sorry, it's actually ImageDateLastMo dified and not ImageDateCreate d,
making the filename:
ImagePath-ImageName-ImageWidth-ImageHeight-
ImageDateLastMo dified.ImageExt ension

The ImageDateLastMo dified will be retreived from a table.column in the
DB.
This is needed to handle cases where the user overwrites the image of
the same file name.

Just curious though, would you know if I use Solution#1: Caching,
will the "Cache Keys" objects be stored in the webserver for use by
other concurrent users?
Thus maximizing cached objects?

Thanks,
Henry Wu

On Jun 14, 7:07 pm, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net
Solution 2 is better, as it doesn't rely on memory tocachethe images.
However, I have one suggestion: You don't need to keep the date created in
theimagefile name. That is an attribute of the file.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net

"wardemon" <henrycorte...@ gmail.comwrote in message

news:11******** **************@ e9g2000prf.goog legroups.com...
Hi All,
I have a aspx page named: ImageProcess.as px that creates a thumbnail
version of animageby passing the ImagePath, width, and height. The
ImagePath is taken from a table from a database, while width and
height is user specific - meaning user can change this on demand.
My question is, although this rendering images on the fly is cool, I
would like to implement some sort of mechanism/logic that it wont keep
rendering the thumbnail again and again.
I thought of two things that might solve my problem, however I am
unsure of the pros and cons and which is much faster for the client.
Solution #1: Caching
----------------------------------
using System.Web.Cach ing;
CacheCache= context.Cache;
//Get theimage
string path =Server.MapPath (Request.FilePa th);
//Check thecache
string key = path + "-" + strWidth + "-" strHeight;
if (Cache[key] != null)
{
Imagecached = (Image)Cache[key];
cached.Save(Res ponse.OutputStr eam,ImageFormat .Jpeg);
return;
}
else
{
Imageimg =Image.FromFile (path);
//Add to thecache
Cache.Add(key, thumb, null, DateTime.Now.Ad dSeconds(10),
TimeSpan.Zero, CacheItemPriori ty.High,
new CacheItemRemove dCallback(this. RemovedCallback ));
}
this solution checks if a "CacheKey" exists for a particular ImagePath
+Width+Height combo exsits, then it uses the "Saved CachedImage", if
none, it will use theimagedirectl y from theImage.FromFi le(path) and
adds a new "CacheKey" for it.
Solution #2: Static Images
----------------------------------
1. Create the staticimagethat was generated on the fly by the
ImageProcess.as px to a directory in the webserver ex: Root
\ThumbnailImage s\
2. The staticimagewill be named as ImagePath-ImageName-ImageWidth-
ImageHeight-ImageDateCreate d.ImageExtensio n
Where
ImagePath =Image'sFull Path taken from a table.column in a db
ImageName =ImageFile Name taken from a table column in a db
ImageWidth = Client User specific
ImageHeight = Client User spefici
ImageDateCreate d =ImageUpload DateTime taken from a table.column in
a db.
3. Subsequent request logic will be:
3.1 First check if the combination filename exists in the Root
\ThumbnailImage s\ folder
3.2 If it exist, use that staticimage
3.2 If it does not exist, createimageon the fly using
ImageProcess.as px & create a thumbnailimagei n the thumbnail Root
\ThumbnailImage s\ folder
I am a bit confuse on which to use. I am after - which is faster ;-)
Lastly, if I use Solution#1: Caching, when the user exists his or her
browser, then opens a new browser, will the "CacheKeys" still be
there? In other words, are the "CacheKeys" stored in the webserver
for use by other concurrent users?
Thanks,
Henry Wu- Hide quoted text -

- Show quoted text -

Jun 14 '07 #3
iis serves up images faster than asp.net can. iis also supports the head
request which the browser will use with images.

-- bruce (sqlwork.com)

wardemon wrote:
Hi All,
I have a aspx page named: ImageProcess.as px that creates a thumbnail
version of an image by passing the ImagePath, width, and height. The
ImagePath is taken from a table from a database, while width and
height is user specific - meaning user can change this on demand.

My question is, although this rendering images on the fly is cool, I
would like to implement some sort of mechanism/logic that it wont keep
rendering the thumbnail again and again.

I thought of two things that might solve my problem, however I am
unsure of the pros and cons and which is much faster for the client.

Solution #1: Caching
----------------------------------
using System.Web.Cach ing;
Cache Cache = context.Cache;

//Get the image
string path = Server.MapPath( Request.FilePat h);

//Check the cache
string key = path + "-" + strWidth + "-" strHeight;
if (Cache[key] != null)
{
Image cached = (Image) Cache[key];
cached.Save(Res ponse.OutputStr eam,ImageFormat .Jpeg);
return;
}
else
{
Image img = Image.FromFile( path);

//Add to the cache
Cache.Add(key, thumb, null, DateTime.Now.Ad dSeconds(10),
TimeSpan.Zero, CacheItemPriori ty.High,
new CacheItemRemove dCallback(this. RemovedCallback ));
}

this solution checks if a "Cache Key" exists for a particular ImagePath
+Width+Height combo exsits, then it uses the "Saved Cached Image", if
none, it will use the image directly from the Image.FromFile( path) and
adds a new "Cache Key" for it.
Solution #2: Static Images
----------------------------------
1. Create the static image that was generated on the fly by the
ImageProcess.as px to a directory in the webserver ex: Root
\ThumbnailImage s\
2. The static image will be named as ImagePath-ImageName-ImageWidth-
ImageHeight-ImageDateCreate d.ImageExtensio n

Where
ImagePath = Image's Full Path taken from a table.column in a db
ImageName = Image File Name taken from a table column in a db
ImageWidth = Client User specific
ImageHeight = Client User spefici
ImageDateCreate d = Image Upload DateTime taken from a table.column in
a db.

3. Subsequent request logic will be:
3.1 First check if the combination filename exists in the Root
\ThumbnailImage s\ folder
3.2 If it exist, use that static image
3.2 If it does not exist, create image on the fly using
ImageProcess.as px & create a thumbnail image in the thumbnail Root
\ThumbnailImage s\ folder
I am a bit confuse on which to use. I am after - which is faster ;-)
Lastly, if I use Solution#1: Caching, when the user exists his or her
browser, then opens a new browser, will the "Cache Keys" still be
there? In other words, are the "Cache Keys" stored in the webserver
for use by other concurrent users?

Thanks,
Henry Wu
Jun 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2670
by: Bill H | last post by:
I have a routine that displays 60 items (with thumbnails) per page. You can click any item and displays a new page with item details. When the user back pages it runs the query again to display all the items. Is there a way to cache that page and images so that second query doesn't execute? I do offer a pop-up window using Java but is not the default and not used by many. I'd really like to get rid of that second query. ;) TIA
11
7529
by: Penelope Baker | last post by:
Greetings: I cannot seem to get IE 6.0 to pre-cache my rollover images. Every time the user rolls over a link, it rereads it from the server, even though it is well into the cache by that time. It works fine in Netscape, Mozilla, Firebird, Firefox, etc. Suggestions? (Other than the obvious one regarding IE :P) Thanks!
4
1711
by: dave | last post by:
hi I'm building a page that displays all phone in phoneview.asp...however from admin section we can add new phone image tht stores path in database. I wanna use cache object in phoneview.asp..becoz most of the time images r same.. so i just need to store image in cache...but not data..becoz asp page reads all phone list information from database and displays all phones... so is it possible to store image in cache so it can be served quickly...
1
3187
by: Glenn | last post by:
Hi, I have a config XML file that I am using from the application cache. I have configured the entry with a remove callback to re-populate cache automatically when the XML file changes. All is well until the XML file is changed. The cached item is being removed as I would expect, but the remove callback is not firing at all, hence a NullReferenceException is being raised when I try to access the cache object. Please see code snippet...
2
474
by: Peter Row | last post by:
Hi, I have a site were the pages are dynamically generated on demand. These pages like any static html page may contain image tags and references to CSS files. All the images and CSS files etc... are stored in a database so in the HTML produced for the page the source of an image, for example, might be: src=http://www.mysite.com/Res/3/logo.gif
6
1443
by: Stephane | last post by:
Hi, All images on my ASP.Net web site are reloaded almost each time I visit a page. My chache setting on IE is set to Automatically. When I visit another web site, images are rarely reloaded so it's fast. This slows down my site and it's really a pain in the neck. All my web pages are dynamic and are built from a database. There no meta field or Response.Expires...
2
2242
by: thehuby | last post by:
I am building a CMS and as part of it a user can upload an image. Once uploaded I am displaying the image. If the user then decides they want to replace the image with another I get a caching issue in the browser as the image has the same name. Without having to use unique file names each time the user replaces an image, how can I force the browser to check for the file properly?
2
5334
by: raji20 | last post by:
I'm frequently updating images on my site when the users clicks on the submit button, and some users have reported they are seeing old images where new ones should be... The image that is getting uploaded is the png image. But the new images gets uploaded and also the old images is getting deleted I assume this is a caching issue. does anyone know of some code I can put into my PHP to clear the cache from certain pages???
1
2237
by: | last post by:
I've built an application that scrapes JPG images of webpages and PDF instances of those webpages automatically from an RSS feed. References to the scraped resources are persisted to our database. I've also built an administrative interface that allows someone to scroll through a datalist of the JPG images of the page and to delete the unwanted items. The JPG previews of the webpage are rendered in several sizes: iconic, mid-sized 600px...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.