NAME

Cache::Memcached::Mock - A mock class for Cache::Memcached

VERSION

version 0.07

SYNOPSIS

Supports only a subset of Cache::Memcached functionality.

my $cache = Cache::Memcached::Mock->new();

# You can also set the limit for the size of the values
# Default real memcached limit is 1Mb
$cache = Cache::Memcached::Mock->new({ size_limit => 65536 }); # bytes

# Or the default bit width when incrementing/decrementing unsigned integers.
$cache = Cache::Memcached::Mock->new({ bit_width => 32 });

# Values are stored in a process global hash
my $value = $cache->get('somekey');
my $set_ok = $cache->set('someotherkey', 'somevalue');
$set_ok = $cache->set('someotherkey', 'somevalue', 60);  # seconds

my $ok = $cache->add('another_key', 'another_value');
$ok = $cache->replace('another_key', 'another_value');

$cache->incr('some-counter');
$cache->decr('some-counter');
$cache->incr('some-counter', 2);

# new() also flushes all values
$cache->flush_all();

my $pairs = $cache->get_multi('key1', 'key2', '...');

DESCRIPTION

This class can be used to mock the real Cache::Memcached object when you don't have a memcached server running (and you don't want to run one actually), but you need the functionality to be there.

I used it in unit tests, where I had to perform several tests against a given memcached instance, to see that certain values were really created or deleted.

Instead of having a memcached instance running for every server where I need unit tests running, or using a centralized memcached daemon, I can just pass a Cache::Memcached::Mock instance wherever a Cache::Memcached one is required.

This is an example of how you would use this mock class:

# Use the "Mock" one instead of C::MC
my $memc = Cache::Memcached::Mock->new();

my $business_object = My::Business->new({
    memcached_instance => $memc
});

$business_object->do_something_that_involves_caching();

In short, this allows you to avoid setting up a real memcached instance whenever you don't necessarily need one, for example unit testing.

NAME

Cache::Memcached::Mock - A mock class for Cache::Memcached

VERSION

version 0.06

AUTHOR

Cosimo Streppone <cosimo@opera.com>
Márcio Faustino <marciof@opera.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Opera Software ASA.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

AUTHOR

Cosimo Streppone <cosimo@opera.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Opera Software ASA.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 279:

Non-ASCII character seen before =encoding in 'Márcio'. Assuming UTF-8