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

<?php
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;
?>

: @ 07:00am
Last Updated: @ 07:00am

There is no comment. Why not be the first?

More Comments/Post Your Own

Advertisement

Online Users

There are 108 users online.

Connect

Connect with us on Facebook

Newsletter

Subscribe to our newsletter for the latest updates and exciting promotions!