Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php simple caching technique for small-mid size websites

I was looking for HTML/Text content caching for small-mid size site using php. I'll mostly save the dynamic navigation-menu for site, generated HTML report from DB etc. Primarily I am looking for session based caching (is it a bad idea?). It can also be file based.

Any existing solution is much appreciated. For example Zend Framework is well known for its loosely coupled components. So, Zend_Cache can be a candidate, but could not find session based caching adapter. Moreover, it is not completely independent component. Can anybody tell what are the classes that I need to take to use Zend_Cache?

Another option is PEAR's - Cache_Lite, whats your take on this?

Is there any other framework, from where I can easily separate the caching component and use it with less learning curve?

Thanks.

like image 730
Hossain Khan Avatar asked Oct 15 '22 13:10

Hossain Khan


1 Answers

Memcached comes to mind, as a really lightweight and efficient solution.

But you can also cache content in simple files. The filesystem is usually fast, and handles read/write locks without problems. And there's no need for any fancy library to handle that...the functions filemtime, file_put_contents and file_get_contents are all you need.

  1. Check if the cache has been written more than N secondes ago with filemtime()
  2. If it's too old, generate the content and write it with file_put_contents()
  3. If not, simply load it wit file_get_contents()

Edit: I'll add a link to that post I made a few months ago : Best Solution for caching. It's not completely on topic, but it might help you in your researchs :)

like image 81
Nicolas Avatar answered Nov 03 '22 02:11

Nicolas