Changeset 71

Show
Ignore:
Timestamp:
05/27/05 16:37:47 (3 years ago)
Author:
ogawa
Message:

Improve image caching with using cache_refresh option

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FlickrPublicPhotos/trunk/FlickrPublicPhotos.pl

    r70 r71  
    6868    my ($ctx, $args) = @_; 
    6969    my $user = $args->{user} or $ctx->error("'user' must be specified"); 
    70  
    71     my @photos = eval { load_photos($user, $args->{refresh} || 3600); }; 
     70    my $refresh = $args->{refresh} || 3600; # default: 1h 
     71    my @photos = eval { load_photos($user, $refresh); }; 
    7272    # if MT::PluginData is unavailable 
    7373    @photos = eval { load_photos_fapi($user); } if $@; 
     
    109109    my $cache = $args->{cache} or return $url; 
    110110    $cache .= '/' unless $cache =~ m!/$!; 
     111    my $refresh = $args->{cache_refresh} || 86400; # default: 24h 
    111112 
    112113    my ($fname) = $url =~ m!^https?://.+/(.*)$!; 
     
    126127    $path .= $fname; 
    127128 
     129    my $mtime = 0; 
     130    if ($fmgr->exists($path)) { 
     131        $mtime = (stat($path))[9]; 
     132        return $site_url if ($refresh && (time - $mtime < $refresh)); 
     133    } 
     134 
    128135    require LWP::UserAgent; 
    129136    require HTTP::Request; 
     
    132139    my $req = HTTP::Request->new(GET => $url); 
    133140    my $ua = LWP::UserAgent->new; 
    134     if ($fmgr->exists($path) && (my $mtime = (stat($path))[9])) { 
    135         $req->header('If-Modified-Since', HTTP::Date::time2str($mtime)); 
    136     } 
     141    $req->header('If-Modified-Since', HTTP::Date::time2str($mtime)) if $mtime; 
    137142    my $rsp = $ua->request($req); 
    138143    if ($rsp->is_success && $rsp->content) {