Cache-Profile
view release on metacpan or search on metacpan
lib/Cache/Profile/CorrelateMissTiming.pm view on Meta::CPAN
package Cache::Profile::CorrelateMissTiming;
# ABSTRACT: Guess the time to compute a cache miss by correlating C<set> and C<get>
our $VERSION = '0.06';
use Moose;
use Guard;
use Time::HiRes 1.84 qw(tv_interval clock gettimeofday);
use namespace::autoclean;
extends qw(Cache::Profile);
has _last_get_timing => (
traits => [qw(Hash)],
isa => "HashRef",
is => "rw",
handles => {
_missed_key => "delete",
_clear_missed => "clear",
},
);
has _in_compute => (
isa => "Bool",
is => "rw",
);
sub compute {
my $self = shift;
scope_guard {
$self->_in_compute(0);
};
$self->_in_compute(1);
$self->SUPER::compute(@_);
}
sub clear {
my $self = shift;
$self->_clear_missed;
$self->SUPER::clear(@_);
}
sub _record_get {
my ( $self, %args ) = @_;
$self->SUPER::_record_get(%args);
return if $self->_in_compute;
my ( @keys, @ret );
if ( $self->cache->isa("Cache::Ref") ) {
# mget by default
@keys = @{ $args{args} };
@ret = @{ $args{ret} };
} else {
@keys = ( $args{args}[0] );
@ret = ( $args{ret}[0] );
}
my %timing;
my %data;
for ( my $i = 0; $i < @keys; $i++ ) {
my ( $key, $value ) = ( $keys[$i], $ret[$i] );
( run in 2.055 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )