Apache-Cache
view release on metacpan or search on metacpan
The namespace associated with this cache.
Defaults to "Default" if not explicitly set.
* "default_lock_timeout" optional, integer
Number of second(s) to wait for locks used each time manipulating
data in the shared memory.
Defaults to not waiting. This means a get() - for expample - on a
temporary locked key - certainely by another process - will return a
FAILED status.
Additionnaly, all Apache::SharedMem parameters are also customizable.
See the Apache::SharedMem manpage.
set (identifier => data, [timeout])
$cache->set(mykey=>'the data to cache', '15 minutes');
if($cache->status & FAILURE)
{
lib/Apache/Cache.pm view on Meta::CPAN
The namespace associated with this cache.
Defaults to "Default" if not explicitly set.
=item *
C<default_lock_timeout> optional, integer
Number of second(s) to wait for locks used each time manipulating data in the shared memory.
Defaults to not waiting. This means a get() - for expample - on a temporary locked
key - certainely by another process - will return a FAILED status.
=back
Additionnaly, all Apache::SharedMem parameters are also customizable. See L<Apache::SharedMem>.
=cut
sub new
{
use Apache::Cache qw(:status);
ok(1);
my $cache1 = new Apache::Cache (cachename=>'TEST');
my $cache2 = new Apache::Cache (cachename=>'TEST');
$cache1->lock;
ok($cache1->status, SUCCESS);
# try to access a locked data
$cache2->set('foo', 'bar');
ok($cache2->status, FAILURE);
# DESTROY should unlock cache1
undef $cache1;
# so data is no longer locked
$cache2->set('foo', 'bar');
ok($cache2->status, SUCCESS);
$cache1 = new Apache::Cache (cachename=>'TEST', default_lock_timeout=>5);
$cache2->lock;
ok($cache2->status, SUCCESS);
my $now = time();
# trying to change the locked data, this will failed, but after 5 seconds
# we want to verify this
$cache1->set('foo', 'bar');
my $now2 = time();
ok($cache1->status, FAILURE);
ok($now2 - $now >= 5);
undef $cache2;
$cache1->clear;
ok($cache1->status, SUCCESS);
( run in 0.545 second using v1.01-cache-2.11-cpan-49f99fa48dc )