Cache-BDB
    
    
  
  
  
view release on metacpan or search on metacpan
lib/Cache/BDB.pm view on Meta::CPAN
    
    return $data->{__data};
}
sub get_bulk {
    my $self = shift;
    my $t = time();
    my $count = 0;
    
    my $db = $self->{__db};
    my $cursor = $db->db_cursor();
    
    my %ret;
    my ($k, $v) = ('','');
    while($cursor->c_get($k, $v, DB_NEXT) == 0) {
      my $d = $self->get($k);
      $ret{$k} = $d if $d;
    }
    $cursor->c_close();
    return \%ret;
}
sub _update_access_time {
    my ($self, $key, $data, $t)  = @_;
    
    my $db = $self->{__db};
    $t ||= time();
    $data->{__last_access_time} = $t;
    
  
  
  lib/Cache/BDB.pm view on Meta::CPAN
      warn "size() currently requires Devel::Size";
      return 0;
    }
    else {
      import Devel::Size qw(total_size);
    }
    
    my ($k, $v) = ('','');
    my $size = 0;
    my $cursor = $self->{__db}->db_cursor();
    while($cursor->c_get($k, $v, DB_NEXT) == 0) {
	$size += total_size($v->{__data});
    }
    $cursor->c_close();
    return $size;
}
##############################################
# Methods for removing items from the cache. #
##############################################
sub remove {
    my ($self, $key) = @_;
    
  
  
  lib/Cache/BDB.pm view on Meta::CPAN
    return $count;
}
sub purge {
    my $self = shift;
    my $t = time();
    my $count = 0;
    
    my $db = $self->{__db};
    my $cursor = $db->db_cursor(DB_WRITECURSOR);
    my ($k, $v) = ('','');
    while($cursor->c_get($k, $v, DB_NEXT) == 0) {
      if($self->__is_expired($v, $t)) {
	$cursor->c_del();
	$count++;
      }
    }
    $cursor->c_close();
    warn "compaction failed!" if $self->_compact();
    return $count;
}
sub __is_expired {
    my ($self, $data, $t) = @_;
    $t ||= time();
    
  
  
  
( run in 0.453 second using v1.01-cache-2.11-cpan-a1d94b6210f )