3

How do you cache image/s with Codeigniter? The images are not being stored in my database.

Thanks!

Chris Harrison
  • 5,512
  • 3
  • 28
  • 36
user634850
  • 515
  • 2
  • 8
  • 16
  • 4
    You need to give more detail than that. Are images stored in a db that need to be cached? – Amir Raminfar Feb 25 '11 at 20:49
  • What do you mean by "cache images" ? Do you generate thumbnails ? Do you want images to be cached on the browser ? Or to avoid loading imagedata from database ? Or ? – Pascal MARTIN Feb 25 '11 at 20:50
  • I'm guessing you're talking about images being stored in a database (and not in a directory on the server - since your question wouldn't make any sense whatsoever)... if they're from a Database, then put this in your controller: $this->output->cache(10); – jpea Feb 25 '11 at 20:51

2 Answers2

6

put this in your controller if you're talking about images being stored in your database:

$this->output->cache(10);

http://codeigniter.com/user_guide/general/caching.html

jpea
  • 3,114
  • 3
  • 26
  • 26
  • 1
    It just caches whatever queries you run within that controller before sending it to the view. If it's in the cache and within the time limit you setup, it'll skip querying the database entirely saving a bunch o' time. Pretty slick. – jpea Feb 25 '11 at 21:13
  • caching image/s not being stored in my database. how? – user634850 Feb 25 '11 at 21:26
  • 1
    it's done automatically by your browser. codeigniter has nothing to do with caching images that are just pulled into your view statically. – jpea Feb 25 '11 at 21:28
0

You can cache the images with mod_expires and Apache. It does not depend on CodeIgniter, it is rather a general solution.

I recommend that you check this link: Website Image Caching with Apache

Community
  • 1
  • 1
Glad To Help
  • 5,299
  • 4
  • 38
  • 56