Show
Ignore:
Timestamp:
06/08/05 15:47:10 (4 years ago)
Author:
ogawa
Message:

Change the modified-time of a cached image if the response is "Not modified"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FlickrPublicPhotos/trunk/FlickrPublicPhotos.pl

    r71 r74  
    11# A plugin for adding "FlickrPublicPhotos" container and related tags 
    22# 
    3 # Release 0.20 (May 26, 2005) 
     3# Release 0.21 (June 6, 2005) 
    44# 
    55# This software is provided as-is. You may use it for commercial or  
     
    1616    $plugin = new MT::Plugin(); 
    1717    $plugin->name("FlickrPublicPhotos Plugin"); 
    18     $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.20"); 
     18    $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.21"); 
    1919    $plugin->doc_link("http://as-is.net/hacks/2005/05/flickrpublicphotos_plugin.html"); 
    2020    MT->add_plugin($plugin); 
     
    5151    } 
    5252    my $data = $pd->data() || {}; 
     53    my $now = time; 
    5354    if (!defined($data->{last_updated}) || !defined($data->{photos}) || 
    54         (time - $data->{last_updated} >= $refresh)) { 
     55        ($now - $data->{last_updated} >= $refresh)) { 
    5556        my @photos = eval { load_photos_fapi($user); }; 
    5657        # if FlickrAPI call fails, reuse cache 
    5758        if (!$@ || !defined($data->{photos})) { 
    5859            $data->{photos} = \@photos; 
    59             $data->{last_updated} = time; 
     60            $data->{last_updated} = $now; 
    6061        } 
    6162        $pd->data($data); 
     
    128129 
    129130    my $mtime = 0; 
     131    my $now = time; 
    130132    if ($fmgr->exists($path)) { 
    131133        $mtime = (stat($path))[9]; 
    132         return $site_url if ($refresh && (time - $mtime < $refresh)); 
     134        return $site_url if ($refresh && ($now - $mtime < $refresh)); 
    133135    } 
    134136 
     
    144146        # put_data, and if can't return original url 
    145147        $fmgr->put_data($rsp->content, $path) or return $url; 
    146         return $site_url; 
     148        $url = $site_url; 
    147149    } elsif ($rsp->code == 304) { # not modified 
    148         return $site_url; 
    149     } else { 
    150         return $url; 
    151     } 
     150        utime $now, $now, $path; # touch it 
     151        $url = $site_url; 
     152    } 
     153    $url; 
    152154} 
    153155