RCACHE

a redis-based cache that supports grouped caching

Download .zip Download .tar.gz View on GitHub

Build Status Coverage Status

Code Example

<?php
require __DIR__."/rcache.php";

# setup your redis conn
$conn = rcache\init('localhost', 6379);

# grouped keys, colon-separated path (under topic-001)
rcache\set($conn, 'topic-01:page-01', 'page-01 text here');
rcache\set($conn, 'topic-01:page-02', 'page-02 text here');
rcache\set($conn, 'topic-01:page-03', 'page-03 text here');

# get a value
$page_01 = rcache\get($conn, 'topic-01:page-01');
$page_02 = rcache\get($conn, 'topic-01:page-02');
$page_03 = rcache\get($conn, 'topic-01:page-03');

# get all values for group
$topic_01 = rcache\get($conn, 'topic-01');

# verify that we have data
var_dump($topic_01, $page_01, $page_02, $page_03);

# invalidate a single key
rcache\invalidate($conn, 'topic-01:page-03');

# this should be null
$page_03 = rcache\get($conn, 'topic-01:page-03');
var_dump($page_03);

# invalidate an entire group of keys
rcache\invalidate($conn, 'topic-01');

# page 01 and 02 should be null, as well as topic 01
$page_01 = rcache\get($conn, 'topic-01:page-01');
$page_02 = rcache\get($conn, 'topic-01:page-02');
$topic_01 = rcache\get($conn, 'topic-01');

# verify that we don't have them anymore
var_dump($topic_01, $page_01, $page_02);

The output would be:

array(3) {
  ["topic-01:page-02"]=>
  string(17) "page-02 text here"
  ["topic-01:page-03"]=>
  string(17) "page-03 text here"
  ["topic-01:page-01"]=>
  string(17) "page-01 text here"
}
string(17) "page-01 text here"
string(17) "page-02 text here"
string(17) "page-03 text here"
NULL
NULL
NULL
NULL

License

MIT - http://noodlehaus.mit-license.org