marcelklehr edited this page Jun 19, 2012 · 11 revisions
Clone this wiki locally

In Zoocache a driver abstracts access to the storage medium. Available storage drivers are:

  • Memcached
  • MySQL
  • File (uses file system)
  • None (no caching; just a dummy)

A driver is a class implementing the Zoo\Driver interface. It should be in the namespace Zoo\Drivers.

Drivers get their name from the file containing them. The class name, however, must be equal to the filename. This name should also be used in config.php to set the driver to be used.

// File: Drivers/MySQL.php
namespace Zoo\Drivers;

class MySQL implements Zoo\Driver
  public function install() {
    // Only executed once, when `install.php` is requested.
    // Leave empty if you don't need it.

  public function get($key) {
    // Should return the stored data.
    // Should return false on error or when the cache entry is expired.

  public store($key, $time_to_live, $data) {
    // Should store $data under $key, with an expiry time of $time_to_live
    // Should return false on error.

  public reset() {
    // Should delete all stored cache snapshots.
    // Should return a false on error.

After the definition of the driver, it must be registered in Zoocache to be used:

Zoo\Cache::$driver = new MyDriver;

Drivers are encouraged to use the Config to retrieve specific settings, but should use their name as a subgroup:

Config::set('', 'bar');