• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Solved) Simple cache question

#1
[eluser]markanderson993[/eluser]
Is there a simple way to eliminate the same image on multiple pages from being loaded each time a user visits a webpage? (witnessing the image actually render from scratch top to bottom on every page) I believe the answer lies with caching the image and serving it from a cache directory but I am having a very hard time learning more about how to do that!

If anyone has any ideas please share!

Thanks a lot!

- Mark

#2
[eluser]Yash[/eluser]
CI has its own [url="http://ellislab.com/codeigniter/user-guide/general/caching.html"]caching[/url]

firefox does it by default for images. also opera support this feature.

#3
[eluser]Eric Cope[/eluser]
The type of caching you are talking about is typically done by the browser. There are Apache directives to tell the browser how long to cache. The CI Caching is different. This "caching" mechanism processes the PHP and stores the output in a regular html file, which then it serves to web browsers. Every so often, the caching mechanism recaches the regular html file to keep things up to date. Does that clarify things?

#4
[eluser]markanderson993[/eluser]
Thanks for your replies, I took what you had to say and applied it to my website but I am still getting images to load from scratch on every page load! To serve the images from a hidden directory I am using a echo(file_get_contents($actual_path_to_image)Wink; system to display the images from a controller. Could this be causing the images to load from scratch every time they are displayed? Hmm

- Mark

#5
[eluser]Eric Cope[/eluser]
That is probably causing your lack of caching. Move one of your images to a public place and see if the caching takes place. Without knowing your setup, I think that is the culprit. Let me know the test results.

#6
[eluser]markanderson993[/eluser]
Well Eric, I'm taking your advice and running with it but I've just got one small question. How can I place a user's image in a public directory and still keep it private so that nobody can access it directly? For instance in sites like facebook or deviantart, they have all these crazy urls with forward and backslashes strewed about and which thwart the user from seeing an image.

Also I was trying to conceptualize a system where if someone wants to view an image, the image is copied to a temporary directory and viewed from there. Does this make sense or should I be having the uploading be done straight to a public directory, not one hidden under root access.

#7
[eluser]Eric Cope[/eluser]
I contemplated the same question several years ago. I thought about copying the files to a temporary location. The disadvantage is that high volume sites require significant disk accesses, which can reduce performance. Back when I first solved this problem, I used htaccess files. I did not like that solution, but it met my needs.

However, let me ask a question from a different point of view. Why do you want a browser to cache an image when you do not want it shared publicly? A similar case to yours (as far as I can tell) would be a stock photo site like istockphoto.com. They sell images, so they do not want their products publicly available. Their solution is to make low resolution watermarked images (you can do this with a php script) publicly available which are cached by browsers. Then, when customers purchase images, they go to a link which does what you do, serves out a photo above the web root. Would this type of solution work for you?

If you share your application, I may be able to offer more targeted advice...

#8
[eluser]markanderson993[/eluser]
Your solution towards image privacy seemed quite viable. I just have one question, how safe would the directories really be? If, as is the case for my site, each user has their own unique 40 char. folder name and their images, audio and video are all stored in that specific folder, could anybody possibly access that folder and view its contents? Or even, could aynone access an image, audio file, or video file directly by typing in the exact URL?

I appreciate your support on my issue. You've been very helpful Smile

- Mark

#9
[eluser]markanderson993[/eluser]
I tried what you said by using a temporary directory (which was a public folder) and I used .htaccess to protect it. However, when I'd try and serve the image up from the website, it would not display. When I deleted my htaccess file, the image did display. How were you able to prevent users from accessing the files directly?

My .htaccess file:

<FilesMatch "\.(htaccess|htpasswd|avi|flv|mp4|jpg|gif|mov|mpeg|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
IndexIgnore *

#10
[eluser]Eric Cope[/eluser]
The php scripts and images were behind the htaccess which prompted the basic authentication process most browsers support. It wasn't elegant, but it worked for my application.

I had a new idea. Browsers only cache images and html output. You could setup a part of your url like this.
Code:
http://yoururl.com/index.php/imageHandlingController/Function/image.jpg

Then, using mod_rewrite, rewrite image.jpg to image.php, which is a php file designed to authenticate a user and then forward on image.jpg.

That might work. It would take some experimenting. I would experiment outside codeIgniter so you are not fighting CI and Apache and your browser.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.