Changeset 238

Show
Ignore:
Timestamp:
03/02/06 15:03:52
Author:
miyagawa
Message:
  • use URI::Fetch for smart caching in OPML and Simple. Fixes #3
  • Switch to Cache::Cache based as a default Cache. Fixes #86
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/Makefile.PL

    r223 r238  
    1818requires('LWP' => 0); 
    1919requires('HTML::Parser' => 3.40); 
     20requires('URI::Fetch' => 0.04); 
    2021 
    2122build_requires(Test::More => 0.42); 
  • trunk/plagger/lib/Plagger/Cache.pm

    r237 r238  
    1111 
    1212    # Cache default configuration 
    13     $conf->{class}  ||= 'Cache::File'; 
     13    $conf->{class}  ||= 'Cache::FileCache'; 
    1414    $conf->{params} ||= { 
    15         cache_root      => File::Spec->catfile($conf->{base}, 'cache'), 
    16         default_expires => '30 minutes', 
     15        cache_root         => File::Spec->catfile($conf->{base}, 'cache'), 
     16        default_expires_in => '30 minutes', 
    1717    }; 
    1818 
     
    3838    } 
    3939 
     40    my $hit_miss = defined $value ? "HIT" : "MISS"; 
     41    Plagger->context->log(debug => "Cache $hit_miss: $_[0]"); 
     42 
    4043    $value; 
    4144} 
     
    4750    my $data = $self->get($key); 
    4851    if (defined $data) { 
    49         Plagger->context->log(debug => "Cache hit: $key"); 
    5052        return $data; 
    5153    } 
    5254 
    53     Plagger->context->log(debug => "Cache miss: $key"); 
    5455    $data = $callback->(); 
    5556    if (defined $data) { 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r189 r238  
    2424    $context->log(info => "Fetch $url"); 
    2525 
    26     my $agent = Plagger::UserAgent->new; 
    27     my $response = $agent->get($url); 
     26    my $agent    = Plagger::UserAgent->new; 
     27    my $response = $agent->fetch($url, $self); 
    2828 
    29     unless ($response->is_success) { 
    30         $context->log(error => "GET $url failed: " . $response->status_line); 
     29    unless ($response) { 
     30        $context->log(error => "GET $url failed: " . $response->status); 
    3131        return; 
    3232    } 
     33 
     34    # TODO: handle 301 Moved Permenently and 410 Gone 
     35    $context->log(debug => $response->status . ": $url"); 
    3336 
    3437    $self->handle_feed($url, \$response->content); 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/OPML.pm

    r117 r238  
    3333    elsif ($uri->scheme =~ /^https?$/) { 
    3434        $context->log(debug => "Fetch remote OPML from $uri"); 
    35         my $response = Plagger::UserAgent->new->get($uri); 
    36         unless ($response->is_success) { 
    37             $context->error("Fetch $uri failed: ". $response->status_line); 
     35 
     36        my $response = Plagger::UserAgent->new->fetch($uri, $self); 
     37        unless ($response) { 
     38            $context->error("Fetch $uri failed: ". $response->status); 
    3839        } 
    3940        $xml = $response->content; 
  • trunk/plagger/lib/Plagger/UserAgent.pm

    r73 r238  
    22use strict; 
    33use base qw( LWP::UserAgent ); 
     4 
     5use URI::Fetch; 
    46 
    57sub new { 
     
    1113} 
    1214 
     15sub fetch { 
     16    my($self, $url, $plugin) = @_; 
     17 
     18    URI::Fetch->fetch($url, 
     19        UserAgent => $self, 
     20        $plugin ? (Cache => $plugin->cache) : (), 
     21    ); 
     22} 
     23 
    13241; 
    1425