Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Drivers

marcelklehr edited this page · 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.

<?php
// 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:

<?php
Zoo\Cache::$driver = new MyDriver;
?>

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

<?php
Config::set('mydriver.foo', 'bar');
?>
Something went wrong with that request. Please try again.