Thx alot for the detailed explanation. I didn't have that big problem with the caching yet, but it is very useful to know.
Michael gmwebs schrieb: > I once had to store images in a database for a client as he absolutely > insisted on it. I also found that serving these images took a lot > longer than just directly accessing the image on the filesystem. > Granted, it was not a Cake application, but the concepts still hold > true. > > One of the drawbacks about storing images in a database is that the > client won't cache these images. This means that each time the same > user requests the page, the images will be retrieved from the database > and the user will endure the same delay. > > Now I am not advocating the use of storing images in the database at > all, but I overcame this issue by implementing a caching system. Some > might say I just duplicated the amount of effort required to achieve > the same result, but my client insisted on storing the images in the > database so I had to come up with a solution that met his requirements > - and served the users of his website in the best possible way. > > The basics of it is as follows: > > 1. write each image from the database to the file system on the server > in a tmp folder > 2. serve each image by requesting the image through a script - <img > src="showimage.php?option=thumb&id=1" /> > 3. in the showimage script, select the image data from the database > 4. check if the modified field from the table is newer than the > temporary image on the file system > 5. if it is, write a new image > 6. if it isn't, set the exisiting image on the file system as the > location > 7. check the headers sent by the client to see if they already have a > copy of the image in their cache > 8. if they do, send 304 not modified and they will see the image they > have stored in their local cache > 9. if they don't, set last-modified header, send 200 OK and render the > image from the server's file system > 10. this ensures that they cache that image in their local cache and > if they browse to the site again it should serve the image from their > local cache if it hasn't changed since the last time > > I know this seems like a lot of work, but it transformed the site from > being unusable to being lightning quick - and my client still had all > his images in the database. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
