Caching with qCache

qEngine support a database cache, called qCache. Caching is very easy with qCache.

1. First, store the cached contents by qcache_update:

function qcache_update ($id, $content)

$id = unique ID.

$content = cached content.

2. Then get the cached content from the database:

function qcache_get ($id)

$id = the unique ID.

Example 1

require './includes/user_init.php';
$cmd = post_param ('cmd');

// try to get the cache
$content = qcache_get ('mycache');
if (!$content)
    // fill with usual code, including mysql query, etc
    // to prove this is cached, we are using randomizer
    // if it's not cached, randomizer should always be changed.
    $sess = random_str(16).'-'.getmicrotime ();
    $content = "<h1>This is a Content</h1>\n";
    $content = "<p>It's now: $sess</p>\n";
    // the store the content
    qcache_update ('mycache', $content);
echo $content;

Posted On: Aug-27-2010 @ 07:00am
Last Updated: Jan-01-1970 @ 07:00am

There is no comment. Why not be the first?

More Comments/Post Your Own