Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to remove images from cache on the Apache side

Posted on 2009-02-11
4
Medium Priority
?
471 Views
Last Modified: 2012-05-06
I have a simple PHP based application on Linux and Apache.

Recently I changed the Logo on home page , but unfortunately the old log image is still rendered and the users have to do a Ctr+f5 to remove the cache to get the new Image.

Is there a way I can remove the cached images on the server side do that the users dont get the old images and dont have to do the ctr+5
0
Comment
Question by:micro_learner
  • 2
4 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 23615052
Change the filename.

> that the users dont get the old images

They don't get them, the browser displays a local cached copy without requesting the image from the server. Otherwise they'd get a fresh copy since the request header If-Modified-Since doesn't match anymore, so the server wouldn't reply with 304 not modified anymore.
0
 

Author Comment

by:micro_learner
ID: 23615347
Thats a great suggestion ..thank you ...but I am using a CMS drupal and that darn stuff has a lot of code ..anyother work around ?
I restarted the apache too ..but dint seem to work ..
 
Thanks for the nifty suggestion though.
 
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23615430
That's on the client side, if the browser doesn't re-request the image but just displays it from disk cache, you can't do something on server side but change the referenced name to force the browser to load that resource from the server. Adding a (useless) QueryString to the image path should be enough. If that's not practicable due to the cms structure I can't see a way to force the browser to reload an already cached resource.

But the cache should expire in some time which will lead the browser to re-request that resource from the server.
0
 
LVL 1

Accepted Solution

by:
Scutty earned 2000 total points
ID: 23739344
Use mod_expires in your apache and set the expiry time for images to be immediate. That way your users browsers and web proxies *shouldn't* cache them and this issue goes away.

Note though this comes with 2 warnings...
1. Your website traffic will increase because every single image request then needs satisfying by your web server, so more server load and more bandiwidth used.
2. Not alll proxies/ web browsers will obey the settings from mod_expires

What I tend to do is set the expiry to be 6 hours for images, I've found it gives me a nice balance between increased traffic and shorter cached file lifetime.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question