PHP Cache Using APC Cache


Example

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.

installation

sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart

Add Cache:

apc_add ($key, $value , $ttl);
$key = unique cache key
$value = cache value
$ttl = Time To Live;

Delete Cache:

apc_delete($key);

Set Cache Example:

if (apc_exists($key)) {
    echo "Key exists: ";
    echo apc_fetch($key);
} else {
    echo "Key does not exist";
    apc_add ($key, $value , $ttl);
}

Performance:

APC is nearly 5 times faster than Memcached.