Hoard
, (*1)
Hoard is a simple, extensible PHP caching library., (*2)
Install
Install via composer:, (*3)
{
"require": {
"gilbitron/hoard": "~0.1.0"
}
}
Run composer install then use as normal:, (*4)
require 'vendor/autoload.php';
$cache = new Hoard\Hoard();
API
Hoard uses the conecpt of "drawers" (as in a chest of drawers) as drivers for caching., (*5)
$cache = new Hoard\Hoard($drawer = 'file', $options = [], $args = []);
Possible drawers (more to come):, (*6)
$options is an array of options passed to the chosen drawer. See Drawers section below., (*7)
$args:
* encrypt_keys - Use encrypted keys (default: true)
* encryption_function - Function to use for encrypting keys md5/sha1 (default: md5), (*8)
Determine if an item exists in the cache, (*9)
$cache->has($key);
Retrieve an item from the cache by key, (*10)
$cache->get($key, $default = null);
Retrieve an item from the cache and delete it, (*11)
$cache->pull($key, $default = null);
Store an item in the cache. $minutes can be an int or DateTime, (*12)
$cache->put($key, $value, $minutes);
Store an item in the cache if the key does not exist. $minutes can be an int or DateTime, (*13)
$cache->add($key, $value, $minutes);
Store an item in the cache indefinitely, (*14)
$cache->forever($key, $value);
Remove an item from the cache, (*15)
$cache->forget($key);
Remove all items from the cache, (*16)
$cache->flush();
Drawers
file
Basic FileSystem caching., (*17)
Options:, (*18)
-
cache_dir - Path to cache directory. Uses the system tmp dir if none provided.
Credits
Hoard was created by Gilbert Pellegrom from Dev7studios. Released under the MIT license., (*19)