473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

crazy cache !!

I've a page where I can upload and delete images.

I've such problem I'm trying to solve. My images are numbered xxxx-1.jpg,
xxxx-2.jpg, xxxx-3.jpg (where xxxx is the article number).

Now, when the used deletes the 2nd pictures, then I update the database for
having the xxxx-3.jpg renamed in xxxx-2.jpg and also I rename the file on
the server.

Problem: if I go to the article page, then the OLD xxxx-2.jpg is shown. I've
to refresh with CTRL pushed to get the correct image. Also if I come back to
manage those pictures again, then the third is definetively removed, and the
xxxx-2.jpg shown the old one, not the xxxx-3.jpg renamed.

How to avoid the server to store such think ? I don't want the cache for
such pictures.

Bob
Nov 22 '05 #1
12 1448
In article <43**********************@news.sunrise.ch>,
"Bob Bedford" <be******@notforspammershotmail.com> wrote:
I've a page where I can upload and delete images.

I've such problem I'm trying to solve. My images are numbered xxxx-1.jpg,
xxxx-2.jpg, xxxx-3.jpg (where xxxx is the article number).

Now, when the used deletes the 2nd pictures, then I update the database for
having the xxxx-3.jpg renamed in xxxx-2.jpg and also I rename the file on
the server.

Problem: if I go to the article page, then the OLD xxxx-2.jpg is shown. I've
to refresh with CTRL pushed to get the correct image. Also if I come back to
manage those pictures again, then the third is definetively removed, and the
xxxx-2.jpg shown the old one, not the xxxx-3.jpg renamed.

How to avoid the server to store such think ? I don't want the cache for
such pictures.


It's the cache in the browser, not the server.
--
Sandman[.net]
Nov 22 '05 #2
your browser is doing the "caching", not the server. add a random
string to the 'src' on the <img> tag. ie <img
src="/myfile-1.jpg?random=<?= rand(1000,9999) ?>" />

Nov 22 '05 #3
There are a number of things you can do, some work better than others
in certain browsers/circumstances. I put them all in, just for luck...

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //
always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); //
HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
Ian

Nov 22 '05 #4
> It's the cache in the browser, not the server.

Well if Bob has:
refresh with CTRL pushed to get the correct image.


Then it can't be browser cache.
I'd say you've made a mistake with your rename or update code. Why
exactly do you need to rename anyway? If you end up with thousands of
images in your database and someone deletes image 1 the server is going
to have to run some very long code and it'll break everyones bookmarks.

Theres nothing wrong having missing ids.
Nov 22 '05 #5
Bob Bedford wrote:
I've a page where I can upload and delete images.

I've such problem I'm trying to solve. My images are numbered xxxx-1.jpg,
xxxx-2.jpg, xxxx-3.jpg (where xxxx is the article number).

Now, when the used deletes the 2nd pictures, then I update the database for
having the xxxx-3.jpg renamed in xxxx-2.jpg and also I rename the file on
the server.


I think one point to make here (unrelated to the actual problem) is
that in general, one should not renumber the IDs of things in a
database when an item is removed.

Unless the ID number has some special significance other than to link
it to a row in the database, then I'd recommend not altering the
numbering, as it's one hell of a lot of housekeeping for no benefit...
(IMHO)

--
Oli

Nov 22 '05 #6
Oliver Saunders writted:
Well if Bob has:
refresh with CTRL pushed to get the correct image.

Then it can't be browser cache.


Why not? Ctrl+refresh forces the download of a new copy of the page

Nov 22 '05 #7
In article <rs******************************@pipex.net>,
Oliver Saunders <ol****@dsl.pipex.com> wrote:
It's the cache in the browser, not the server.


Well if Bob has:
refresh with CTRL pushed to get the correct image.


Then it can't be browser cache.


Read it again. He is hitting CTRL to get the correct image. I.e. that's when it
works. That is the sign that this is indeed browser cache problems.

--
Sandman[.net]
Nov 22 '05 #8
> Read it again. He is hitting CTRL to get the correct image. I.e. that's when it
works. That is the sign that this is indeed browser cache problems.


Yes quite right sorry. Not doing very well today.
Nov 22 '05 #9

"Ian B" <ia********@gmail.com> a écrit dans le message de news:
11********************@g49g2000cwa.googlegroups.co m...
Oliver Saunders writted:
Well if Bob has:
refresh with CTRL pushed to get the correct image.

Then it can't be browser cache.


Why not? Ctrl+refresh forces the download of a new copy of the page

Yes it's browser cache. So how to not cache them ?
Nov 22 '05 #10
Bob - see black francis' answer above. Append a random number to the
end of the image src. This will then force the browser to thinking it
is a new image and download a fresh copy.

Nov 22 '05 #11
Bob roted recently:
Yes it's browser cache. So how to not cache them ?


Put in any/all of the headers I mentioned in my first answer

Ian

Nov 22 '05 #12
I've found this method to be very unreliable depending on which browser
you're using - especially Internet Explorer. Also these headers will
prevent any of the page content from caching - not just the images
which will force reload every time a visitor hits the page - this can
obviously slow down the browsing of the site and increase server load.

Nov 22 '05 #13

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

Similar topics

11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
9
by: Jimnbigd | last post by:
Here's a Crazy Eights game. This was fun to write. So far it only works in IE. I'm working on a Netscape version. I haven't installed other browers (yet). I'm open to comments and suggestions....
3
by: martin | last post by:
Hi, I am storing a dataset in cache, which is happening fine. I can easily retrive it at postback from the cache, cast it to a dataset and reuse it. However I have specified that the cache...
2
by: sklett | last post by:
I keep my solution on my iPod and today I made some changes at work, then I got home and opened the solution in vis studio and the changes were all there(normal) When I debug, it shows me old...
14
by: Tom.PesterDELETETHISSS | last post by:
Hi, I think this question requires an in depth understanding of how a browser cache works. I hope I can reach an expert here. I may have found a quirk in the asp.net documentation or I don't...
3
by: andyjgw | last post by:
Hi I posted this in the caching section, before noticing that it appears to be a practically dead NG, so please excuse the x-post... Can anyone advise on this please? Something is happening...
0
by: mateipuiu | last post by:
When a try to run a client build on 2005, which uses the Microsoft.ApplicationBlocks.Cache.dll reference, when using a Microsoft.ApplicationBlocks.Cache.dll created on Debug mode, the client works...
3
by: squash | last post by:
I have spent two hours trying to make sense of this script, called crazy.php. The output should be nothing because $cookie_password is nowhere defined in this script, correct? But it actually...
11
by: shapper | last post by:
Hello, I am creating a centered web site with various div's inside the main (pBase) div. Somehow, I am getting a gap on the top of my browser window both in IE and Firefox. I tried...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.