Cache::Memcached::Mock - A mock class for Cache::Memcached
version 0.07
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', '...');
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.
version 0.06
Cosimo Streppone <cosimo@opera.com> Márcio Faustino <marciof@opera.com>
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.
Cosimo Streppone <cosimo@opera.com>
This software is copyright (c) 2013 by Opera Software ASA.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'Márcio'. Assuming UTF-8
To install Cache::Memcached::Mock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Memcached::Mock
CPAN shell
perl -MCPAN -e shell install Cache::Memcached::Mock
For more information on module installation, please visit the detailed CPAN module installation guide.