PEAR::Cache_lite - speed, simplicity, security

One way to speed up web application is to lower database usage. Databases designed to provide very fast manipulation with data in files. Often developer use databases for everything and store session data, user files. This action make tables big and database server work slowly... As result an simple file based cache will speed up application very quick.

An simple example what we can do with Cache_lite:

// Include the package
$id = 'example_id';
$options = array(
    'cacheDir' => '/tmp/', // directory where cache files will be stored
    'lifeTime' => 3600 // expired time
$Cache_Lite = new Cache_Lite($options);
// Test if there is a valid cache for this id
if (!$data = $Cache_Lite->get($id)) {
    // Cache miss !
    // multiple sql queries or high load functionality put generated content to data
    $data = get_generated_content();
    // save generated content
echo $data;

Simple and efficient. Variable data will contain string, so if you need to store objects just use serialize

Trackback URL for this post: