Zend Framework - Cache module (quick review)
I've just about finished writing an article for Linux User & Developer which is an introduction to the Zend Framework's Cache module.
Caching is something I've been meaning to look at for some time, especially as one customer could benefit from it due to some expensive queries and data manipulation that take place. As is life, I've some how managed to avoid actually looking into it properly, until yesterday anyway.
Firstly, it was really easy to get a simple example up and running - about 10 lines of code gives a working example, caching data to a temporary file.
<?php
require_once('Zend/Cache.php');
$backend = 'File';
$frontend = 'Core';
$cache = Zend_Cache::factory($frontend, $backend);
$data = $cache->load('hello_world');
if($data !== FALSE) {
echo "Data in cache : $data \n";
}
else {
echo "Caching data....\n";
$cache->save("Hello World : " . date('U'), 'hello_world');
}
?>
The Cache module has been well designed, with a clever seperation of Frontend and Backend. This makes it very flexible, and in my case also makes it very easy to change to backends as the application grows and scales (e.g. starting at File, moving to APC or Sqlite and then memcached).
It is very easy to get started with, and has no dependencies on the rest of the Zend framework, so can easily slot into an existing application and code base.
Looking at Zend Cache has been on my todo list for some months now, and after finally looking into it, I'm glad and pleased with what I've found.
Comments
sample code
Sample code is online at Pale Purple
Post new comment