NAME

Slick::Cache

SYNOPSIS

A wrapper around a Slick::CacheExecutor that either implements Redis or Cache::Memcached.

use 5.036;

use Slick;

my $s = Slick->new;

# See Redis and Cache::Memcached on CPAN for arguments

# Create a Redis instance
$s->cache(
    my_redis => type => 'redis',    # Slick Arguments
    server   => '127.0.0.1:6379'    # Cache::Memcached arguments
);

# Create a Memcached instance
$s->cache(
    my_memcached => type          => 'memcached',   # Slick Arguments
    servers      => ['127.0.0.1'] => debug => 1     # Cache::Memcached arguments
);

$s->cache('my_redis')->set( something => 'awesome' );

$s->get(
    '/foo' => sub {
        my ( $app, $context ) = @_;
        my $value = $app->cache('my_redis')->get('something');  # Use your cache
        return $context->text($value);
    }
);

$s->run;

API

raw

Returns the underlying Redis or Cache::Memcached objects.

set

$s->cache('my_cache')->set(something => 'awesome');

Sets a value in the cache. Note, this is a facade for Redis->set or Cache::Memcached->set.

get

$s->cache('my_cache')->get('something');

Gets a value from the cache, returns undef if it that key does not exist. Note, this is a facade for Redis->get or Cache::Memcached->get.

incr

$s->cache('my_cache')->incr('value');

Attempts to increment a value in the cache.

decr

$s->cache('my_cache')->decr('value');

Attempts to decrement a value in the cache.

See also

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 123:

Unknown directive: =over2

Around line 125:

'=item' outside of any '=over'