Cache problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Cache problems

Post by bob_the _builder »

Hi,

Im prolly not posting in the correct place ..

I have a cache problem with my image gallerys and members image in their profile.

If a member changes their picture (using php + gd script) then hit the link to view thier profile the old image shows untill a page refresh is performed.

Same when they upload an image, I display a preview of the uploaded image with the success message, this also shows cached images often.

Can this be stopped?


Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Change the filename. For instance, phpBB stores the images as a hash result. What you hash could be the results of microtime() for example.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Ahh, I have it so it changes the image name to the users id + filetype prior to storing it in the database.

When they update it, basiaclly the existing image gets unlinked and updates the name with the userid + file extension.

Is there away to stop the cache problem keeping the naming stucture of the uploads.


Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You could shift the image link to a script (that outputs caching control headers) or add a randomized query string to the URL that makes no difference in the actual request, but does affect the knowledge of the browsers' caching mechanisms.
Post Reply