Cache-RamDisk
view release on metacpan or search on metacpan
lib/Cache/RamDisk.pm view on Meta::CPAN
}
Later on in a cgi script:
use CGI qw(:html);
use Cache::RamDisk::Functions;
[...]
my $s = cache_status ('/tmp/rd');
[...]
print "Number of items for 'fie': ".$s->key_stat('fie'), br;
On application shutdown:
cache_remove ('/tmp/rd');
=head1 DESCRIPTION
I<Note: 'rd' is from now on in this document an abbreviation for 'ramdisk' or 'RAM Disk' or however you prefer
lib/Cache/RamDisk.pm view on Meta::CPAN
$rdpath = $self->{Base}.$rdpath;
unlink $rdpath;
}
}
$idx ||= "";
$idx =~ s/(\d+\/\/$id)\n//s if $idx; # "splice" ...
$rdpath = $1 || "";
# remove an existing item (items are stored as a whole on one disk and not broken up, and as we
# secondly have to stat() an existing item anyway in order to compare the sizes, and after this
# comparison maybe ++have++ to delete the old item, we just remove it right here):
if ($rdpath) {
$rdpath =~ s/\/\//\/$k\//;
$rdpath = $self->{Base}.$rdpath;
$key[1]--;
unlink $rdpath;
}
$item = Storable::freeze($what->{$k}->{$id});
$l = length $item;
# find a free rd (__DStart__: new in 0.1.5, see Functions.pm)
lib/Cache/RamDisk/Functions.pm view on Meta::CPAN
=head3 What happened?
cd /tmp/rd0 && ls -la
ipcs
=head2 cache_status ( $basename [, $shmemkey] )
my $s = cache_status('/tmp/rd');
print $s->key_stat('fie');
print $s->rd_stat(0)->{bavail};
The monitoring tool for a running cache. Requires the cache's base pathname (-fragment, see cache_install), and
the 'ShMem' key for this cache, if another than the default value 'RdLk' had been chosen.
Always (!) returns a Class::Struct reference with the following accessible members:
$s->error # contains the error message in case something went wrong
$s->start_disk # the index of the first rd allocated
$s->disks # the total of allocated disks
$s->blocksize # guess what
$s->keys # a key's limit, as set in 'Keys'
lib/Cache/RamDisk/Functions.pm view on Meta::CPAN
$stat->disks($cache{__Disks__});
$stat->blocksize($cache{__BSize__});
$stat->start_disk($cache{__DStart__}); # new in 0.1.5
# 2. key infos:
my @key;
foreach (keys %cache) {
unless (/^__.*__/) {
@key = split /:/, $cache{$_};
$stat->keys($_, $key[0]);
$stat->key_stat($_, $key[1]);
}
}
$tie->shunlock;
# 3. disk infos:
for (my $i = $stat->start_disk; $i < $stat->disks+$stat->start_disk; $i++) {
$stat->rd_stat($i, df($rdpath.$i));
}
undef $tie;
untie %cache;
$stat;
}
# new in 0.1.6: monitoring tool, pt.2:
sub cache_objects {
$c->invalidate({'fie' => 1});
if ($c->errstr) {
warn $c->errstr;
print "not ok \n";
exit 0;
}
print "ok 3 \n";
$c = cache_status('/tmp/cachetest/rd');
unless ($c || $c->key_stat('fie') != 199) {
print "not ok \n";
exit 0;
}
print "ok 4 \n";
$c = Cache::RamDisk->new ('/tmp/cachetest/rd', CACHE_LRU);
for (my $i = 0; $i < 660; $i++) {
if ($i % 2) {
last unless $c->get({'fie' => $i });
( run in 0.675 second using v1.01-cache-2.11-cpan-49f99fa48dc )