NAME
DBIx::Fast::Cache::Redis - Redis backend for DBIx::Fast's result cache
SYNOPSIS
use Redis::Fast;
use DBIx::Fast::Cache::Redis;
my $db = DBIx::Fast->new(
dsn => $dsn,
cache => {
default_ttl => 300,
backend => DBIx::Fast::Cache::Redis->new(
redis => Redis::Fast->new(server => '127.0.0.1:6379'),
prefix => 'myapp:dbcache:',
),
},
);
my $promos = $db->cached(tag => 'promos')->all('SELECT * FROM promos');
$db->invalidate('promos'); # seen by every process using this Redis
DESCRIPTION
Stores DBIx::Fast::Cache entries in Redis, so every process (preforked web workers, job workers, scripts) shares one cache and one set of tags: an invalidate anywhere makes the tagged entries miss everywhere. The cache runs in shared mode with this backend: each tag has a version counter in Redis (INCR), entries record the versions they were stored under, and a read checks them (one extra GET per tag of the entry).
Values are serialized as JSON (Cpanel::JSON::XS, JSON::PP as a fallback), so cached results must be plain data - which query results are. Entries get the cache's TTL as a Redis expiry (SET ... EX).
METHODS
new
DBIx::Fast::Cache::Redis->new(redis => $client, prefix => 'dbixfast:');
redis is an already connected Redis::Fast or Redis object; prefix namespaces every key (default dbixfast:).
get, set, remove, incr
The backend interface used by DBIx::Fast::Cache.
clear
Deletes every key under the prefix, with SCAN (never KEYS).
supports_ttl
True: the cache passes its TTL to set.
redis, prefix
Readers for the constructor arguments.
SEE ALSO
DBIx::Fast::Cache, "cached" in DBIx::Fast, Redis::Fast
AUTHOR
SeHarrys
LICENSE
This is free software under the Artistic License 2.0.