Skip to content

Commit

Permalink
cache retrieval has to happen after the params for the request have b…
Browse files Browse the repository at this point in the history
…een sorted out, so iterated requests can work properly
  • Loading branch information
wchristian committed Nov 25, 2011
1 parent 549d938 commit 4f1c9e7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/Net/LastFMAPI.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -202,22 +202,6 @@ sub lastfm {
my ($method, @params) = @_; my ($method, @params) = @_;
$method = lc($method); $method = lc($method);


my $cache = $cache;
if ($cache) {
unless (-d $cache) {
$cache = $cache_dir;
make_path($cache);
}
my $file = "$cache/".md5_hex(encode_json(\@_));
if (-f $file) {
my $data = loadfile($file);
return _rowify_content( $data->{content} );
}
else {
$cache = $file
}
}

my %params; my %params;
my $i = 0; my $i = 0;
while (my $p = shift @params) { while (my $p = shift @params) {
Expand Down Expand Up @@ -249,6 +233,23 @@ sub lastfm {
sign(\%params); sign(\%params);


%last_params = %params; %last_params = %params;

my $cache = $cache;
if ( $cache ) {
unless ( -d $cache ) {
$cache = $cache_dir;
make_path( $cache );
}
my $cache_key_json = encode_json( [ map { $_, $params{$_} } sort keys %params ] );
my $file = "$cache/" . md5_hex( $cache_key_json );
if ( -f $file ) {
my $data = loadfile( $file );
return _rowify_content( $data->{content} );
}

$cache = $file;
}

my $res; my $res;
if ($methods->{$method}->{post}) { if ($methods->{$method}->{post}) {
$res = $ua->post($url, Content => \%params); $res = $ua->post($url, Content => \%params);
Expand Down

0 comments on commit 4f1c9e7

Please sign in to comment.