Php Simple Caching Technology for Small Sites

I was looking for caching HTML / Text content for a small site using php. I basically save the dynamic navigation menu for the site, the generated HTML report from the database, etc. First of all, I'm looking for session-based caching (is this a bad idea?). It can also be file based.

Any existing solution is greatly appreciated. For example, the Zend Framework is well known for its loosely coupled components. Thus, Zend_Cache may be a candidate, but could not find a session-based cache adapter. Moreover, it is not a fully independent component. Can anyone tell me which classes I need to use to use Zend_Cache?

Another option is PEAR - Cache_Lite, what do you take on?

Is there any other structure where I can easily separate the caching component from and use it with a lesser learning curve?

Thanks.

+5
source share
5 answers

Memcached comes to mind as a really easy and effective solution.

But you can also cache content in simple files. The file system usually works quickly and handles read / write locks without problems. And there is no need for any fancy library to handle this ... the filemtime , file_put_contents and file_get_contents functions are all you need.

  • Check if the cache was written more than N seconds ago with the file ()
  • , file_put_contents()
  • , file_get_contents()

: , : . , :)

+2

, , . , ( ).

APC , , , Zend_Cache APC . APC , Zend_Cache back-end /

+1
+1

CakePHP. , , , .

0

php . .

<?php

function callback($buffer)
{
  // Code to store output in cache
}

if (/* Test cached copy is still valid */) {
    /* Output cached copy to browser */
    exit(0);
}

ob_start("callback");
?>

<html>...</html>

<?php
ob_end_flush();
?>

ob_end_flush(), , .

It is interesting to note that this structure can be wrapped around smaller units than a page. For example, you specify caching only the navigation menu. You will need a little more logic for the cache, but the principle is the same.

0
source

All Articles