Basic Usage

Below is a simple example using the File adapter. See the other adapters for more info.

<?php
include 'vendor/autoload.php';

use Vespula\Cache\Adapter\File as FileCache;

$path = '/some/path/cache'; // read and write by web server, or PHP process

// The default TTL can be an integer(seconds), a DateInterval, or null (no expiry).
$default_ttl = 3600; // 3600 seconds

$adapter = new FileCache($path, $default_ttl);

// Set a value by key with key-specific ttl (optional)
$adapter->set('cat', 'meow', 1800);

// returns 'meow' if still in cache
$value = $adapter->get('cat');

// returns 'meow' if still in cache, or 'some default' if not.
$value = $adapter->get('cat', 'some default');

// set multiple entries
$values = [
    'foo'=>'Value A',
    'bar'=>'Value B'
];

$adapter->setMultiple($values);

// Or specify a different TTL for these values (different than the default)
$adapter->setMultiple($values, 1800);


// Delete a value by key
$adapter->delete('cat');

// Delete multiples
$keys = [
    'foo',
    'bar'
];

$adapter->deleteMultiple($keys);

// Check for presence in the cache
$is_cached = $adapter->has($key);

// Delete all entries in the cache
$adapter->clear();

// Update the expiry on an item
$ttl = 1800;
$key = 'cat';
$adapter->touch($key, $ttl);